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"*/
18 Examples of **correct** code for this rule:
21 /*eslint no-redeclare: "error"*/
30 This rule takes one optional argument, an object with a boolean property `"builtinGlobals"`. It defaults to `true`.
31 If set to `true`, this rule also checks redeclaration of built-in globals, such as `Object`, `Array`, `Number`...
35 The `"builtinGlobals"` option will check for redeclaration of built-in globals in global scope.
37 Examples of **incorrect** code for the `{ "builtinGlobals": true }` option:
40 /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
45 Examples of **incorrect** code for the `{ "builtinGlobals": true }` option and the `browser` environment:
48 /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
49 /*eslint-env browser*/
54 The `browser` environment has many built-in global variables (for example, `top`). Some of built-in global variables cannot be redeclared.
56 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.
60 * [no-shadow](no-shadow.md)