TypeError: variable "x" redeclares argument - JavaScript 编辑
The JavaScript strict mode-only exception "variable redeclares argument" occurs when the same variable name occurs as a function parameter and is then redeclared using a var
assignment in a function body again.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论