Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript SyntaxError – Redeclaration of formal parameter “x”

  • Last Updated : 24 Jul, 2020

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:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

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



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!