no-shadow-restricted-names
Recommended
Disallows shadowing of restricted names.
Disallows shadowing of restricted names.
The following (a) properties of the global object, or (b) identifiers are "restricted" names in JavaScript:
These names are NOT reserved in JavaScript, which means that nothing prevents
one from assigning other values into them (i.e. shadowing). In other words, you
are allowed to use, say, undefined
as an identifier or variable name. (For
more details see MDN)
function foo() {
const undefined = "bar";
console.log(undefined); // output: "bar"
}
Of course, shadowing like this most likely confuse other developers and should be avoided. This lint rule detects and warn them.
Invalid:
const undefined = 42;
function NaN() {}
function foo(Infinity) {}
const arguments = () => {};
try {
} catch (eval) {}
Valid:
// If not assigned a value, `undefined` may be shadowed
const undefined;
const Object = 42;
function foo(a: number, b: string) {}
try {
} catch (e) {}