Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

TypeError: variable "x" redeclares argument

Naši dobrovolníci ještě tento článek do jazyka Čeština nepřeložili. Přidejte se a pomozte nám tuto práci dokončit!

Message

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.

Examples

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

Štítky a přispěvatelé do dokumentace

 Přispěvatelé této stránky: fscholz
 Poslední aktualizace od: fscholz,