JavaScript SyntaxError – Redeclaration of formal parameter “x”

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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!



