]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/no-catch-shadow.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / no-catch-shadow.md
1 # Disallow Shadowing of Variables Inside of catch (no-catch-shadow)
2
3 This rule was **deprecated** in ESLint v5.1.0.
4
5 In IE 8 and earlier, the catch clause parameter can overwrite the value of a variable in the outer scope, if that variable has the same name as the catch clause parameter.
6
7 ```js
8 var err = "x";
9
10 try {
11 throw "problem";
12 } catch (err) {
13
14 }
15
16 console.log(err) // err is 'problem', not 'x'
17 ```
18
19 ## Rule Details
20
21 This rule is aimed at preventing unexpected behavior in your program that may arise from a bug in IE 8 and earlier, in which the catch clause parameter can leak into outer scopes. This rule will warn whenever it encounters a catch clause parameter that has the same name as a variable in an outer scope.
22
23 Examples of **incorrect** code for this rule:
24
25 ```js
26 /*eslint no-catch-shadow: "error"*/
27
28 var err = "x";
29
30 try {
31 throw "problem";
32 } catch (err) {
33
34 }
35
36 function err() {
37 // ...
38 };
39
40 try {
41 throw "problem";
42 } catch (err) {
43
44 }
45 ```
46
47 Examples of **correct** code for this rule:
48
49 ```js
50 /*eslint no-catch-shadow: "error"*/
51
52 var err = "x";
53
54 try {
55 throw "problem";
56 } catch (e) {
57
58 }
59
60 function err() {
61 // ...
62 };
63
64 try {
65 throw "problem";
66 } catch (e) {
67
68 }
69 ```
70
71 ## When Not To Use It
72
73 If you do not need to support IE 8 and earlier, you should turn this rule off.