src/content/docs/linter/rules/no-shadow.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Rule available since: `v2.0.0` - Diagnostic Category: [`lint/nursery/noShadow`](/reference/diagnostics#diagnostic-category) - This rule doesn't have a fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`no-shadow`](https://eslint.org/docs/latest/rules/no-shadow){
"linter": {
"rules": {
"nursery": {
"noShadow": "error"
}
}
}
}
Disallow variable declarations from shadowing variables declared in the outer scope.
Shadowing is the process by which a local variable shares the same name as a variable in its containing scope. This can cause confusion while reading the code and make it impossible to access the global variable.
See also: noShadowRestrictedNames
const foo = "bar";
if (true) {
const foo = "baz";
}
Variable declarations in functions can shadow variables in the outer scope:
const foo = "bar";
const bar = function () {
const foo = 10;
}
Function argument names can shadow variables in the outer scope:
const foo = "bar";
function bar(foo) {
foo = 10;
}
const foo = "bar";
if (true) {
const qux = "baz";
}