1 # disallow variable redeclaration (no-redeclare)
3 In JavaScript, it's possible to redeclare the same variable name using `var`. This can lead to confusion as to where the variable is actually declared and initialized.
7 This rule is aimed at eliminating variables that have multiple declarations in the same scope.
9 Examples of **incorrect** code for this rule:
12 /*eslint no-redeclare: "error"*/
30 Examples of **correct** code for this rule:
33 /*eslint no-redeclare: "error"*/
54 This rule takes one optional argument, an object with a boolean property `"builtinGlobals"`. It defaults to `true`.
55 If set to `true`, this rule also checks redeclaration of built-in globals, such as `Object`, `Array`, `Number`...
59 The `"builtinGlobals"` option will check for redeclaration of built-in globals in global scope.
61 Examples of **incorrect** code for the `{ "builtinGlobals": true }` option:
64 /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
69 Examples of **incorrect** code for the `{ "builtinGlobals": true }` option and the `browser` environment:
72 /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
73 /*eslint-env browser*/
78 The `browser` environment has many built-in global variables (for example, `top`). Some of built-in global variables cannot be redeclared.
80 Note that when using the `node` or `commonjs` environments (or `ecmaFeatures.globalReturn`, if using the default parser), the top scope of a program is not actually the global scope, but rather a "module" scope. When this is the case, declaring a variable named after a builtin global is not a redeclaration, but rather a shadowing of the global variable. In that case, the [`no-shadow`](no-shadow.md) rule with the `"builtinGlobals"` option should be used.
84 * [no-shadow](no-shadow.md)