Skip to content

Commit 909c727

Browse files
authored
Docs: Add valid example that shows vars in a block scope (#14230)
* Docs: Add valid example that shows vars in a block scope All the current valid examples show hoisting the var to the function scope. This example makes is clear that this rule allows you to declare vars inside a block scope, just not use them out of that scope. * Docs: Add corresponding invalid example to block-scoped-var
1 parent 28583eb commit 909c727

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

docs/rules/block-scoped-var.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ function doTryCatch() {
3434
var f = build;
3535
}
3636
}
37+
38+
function doFor() {
39+
for (var x = 1; x < 10; x++) {
40+
var y = f(x);
41+
}
42+
console.log(y);
43+
}
3744
```
3845

3946
Examples of **correct** code for this rule:
@@ -71,6 +78,13 @@ function doTryCatch() {
7178
f = build;
7279
}
7380
}
81+
82+
function doFor() {
83+
for (var x = 1; x < 10; x++) {
84+
var y = f(x);
85+
console.log(y);
86+
}
87+
}
7488
```
7589

7690
## Further Reading

0 commit comments

Comments
 (0)