]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/no-shadow-restricted-names.md
890353da787a0ae4106a25e1c0234a9627433f0a
[pve-eslint.git] / eslint / docs / rules / no-shadow-restricted-names.md
1 # Disallow Shadowing of Restricted Names (no-shadow-restricted-names)
2
3 ES5 §15.1.1 Value Properties of the Global Object (`NaN`, `Infinity`, `undefined`) as well as strict mode restricted identifiers `eval` and `arguments` are considered to be restricted names in JavaScript. Defining them to mean something else can have unintended consequences and confuse others reading the code. For example, there's nothing preventing you from writing:
4
5 ```js
6 var undefined = "foo";
7 ```
8
9 Then any code used within the same scope would not get the global `undefined`, but rather the local version with a very different meaning.
10
11 ## Rule Details
12
13 Examples of **incorrect** code for this rule:
14
15 ```js
16 /*eslint no-shadow-restricted-names: "error"*/
17
18 function NaN(){}
19
20 !function(Infinity){};
21
22 var undefined = 5;
23
24 try {} catch(eval){}
25 ```
26
27 Examples of **correct** code for this rule:
28
29 ```js
30 /*eslint no-shadow-restricted-names: "error"*/
31
32 var Object;
33
34 function f(a, b){}
35
36 // Exception: `undefined` may be shadowed if the variable is never assigned a value.
37 var undefined;
38 ```
39
40 ## Further Reading
41
42 * [Annotated ES5 - §15.1.1](https://es5.github.io/#x15.1.1)
43 * [Annotated ES5 - Annex C](https://es5.github.io/#C)
44
45 ## Related Rules
46
47 * [no-shadow](no-shadow.md)