We're looking for a person or people to help audit MDN to find places we could speed up. Is this you or someone you know? Check out the RFP: https://mzl.la/2IHcMiE

Our volunteers haven't translated this article into 한국어 yet. Join us and help get the job done!
You can also read the article in English (US).


TypeError: variable "x" redeclares argument (Firefox)

Error type

TypeError warning in strict mode only.

What went wrong?

The same variable name occurs as a function parameter and is then redeclared using a var assignment in a function body again. This might be a naming conflict and thus JavaScript warns about it.

This error occurs as a warning in strict mode code only. In non-strict code, the redeclaration is silently ignored.


Invalid cases

In this case, the variable "arg" redeclares the argument.

'use strict';

function f(arg) { 
  var arg = 'foo'; 

Valid cases

To fix this warning, the var statement can just be omitted, because the variable exists already. In other cases, you might to rename either the function parameter or the variable name.

'use strict';

function f(arg) {
  arg = 'foo';

See also

문서 태그 및 공헌자

 이 페이지의 공헌자: nmve, fscholz
 최종 변경: nmve,