JavaScript TypeError – Variable “x” redeclares argument

This JavaScript exception variable redeclares argument occurs in strict-mode only and if the variable name which is also function parameter has been redeclared with the var keyword.

Message:

TypeError: variable "x" redeclares argument (Firefox)

Error Type:

TypeError

Cause of the Error: A variable which is the parameter of the function has been re-declared with the var keyword inside the function.

Example 1: In this example, the variable(‘varName’) has been redeclared.



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
'use strict';
function fun(varName) { 
  var varName = 'This is GFG'; // Error Here 
}
</script>

chevron_right


Output:

TypeError: variable "varName" redeclares argument

Example 2: In this example, the variable(‘argName’) has been redeclared and function is called as well.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
'use strict';
function fun2(argName) { 
  var argName = 'This is gfg'; // Error Here 
}
fun2('This is GeeksFooGeeks');
</script>

chevron_right


Output:

TypeError: variable "argName" redeclares argument

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.