Skip to content

Commit

Permalink
Docs: Add valid example that shows vars in a block scope (#14230)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
edg2s committed Mar 25, 2021
1 parent 28583eb commit 909c727
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/rules/block-scoped-var.md
Expand Up @@ -34,6 +34,13 @@ function doTryCatch() {
var f = build;
}
}

function doFor() {
for (var x = 1; x < 10; x++) {
var y = f(x);
}
console.log(y);
}
```

Examples of **correct** code for this rule:
Expand Down Expand Up @@ -71,6 +78,13 @@ function doTryCatch() {
f = build;
}
}

function doFor() {
for (var x = 1; x < 10; x++) {
var y = f(x);
console.log(y);
}
}
```

## Further Reading
Expand Down

0 comments on commit 909c727

Please sign in to comment.