Skip to content
Related Articles

Related Articles

JavaScript SyntaxError – Redeclaration of formal parameter “x”
  • Last Updated : 24 Jul, 2020
GeeksforGeeks - Summer Carnival Banner

This JavaScript exception redeclaration of formal parameter occurs if a variable name is a function parameter and also declared again inside the function body using a let assignment.

Message:

SyntaxError: Let/Const redeclaration (Edge)
SyntaxError: redeclaration of formal parameter "x" (Firefox)
SyntaxError: Identifier "x" has already been declared (Chrome)

Error Type:

SyntaxError

Cause of Error:  In a function declaration, a variable name in the function parameter and inside the function body, same variable name declared using a let assignment.

Example 1: In this example, the ‘let’ keyword is used to re-declare the parameter variable, So the error has occurred.



HTML




<!DOCTYPE html>
<html>
<head>
    <title>Syntax Error</title>
</head>
<body>
    <script>
    function GFG(var_name) { 
      let var_name = 'This is GFG';
      return var_name;
    }
    document.write(GFG());
    </script>
</body>
</html>

Output(In console):

SyntaxError: Let/Const redeclaration

Example 2: In this example, the ‘const’ keyword is used to re-declare the parameter variable, So the error has occurred.

HTML




<!DOCTYPE html>
<html>
<head>
    <title>Syntax Error</title>
</head>
<body>
    <script>
    function GFG(var_name) { 
      const var_name = 12345;
      return var_name;
    }
    document.write(GFG());
    </script>
</body>
</html>

Output(In console):

SyntaxError: Let/Const redeclaration

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :