From fc835c18d1596e018969e0ac101d1aac8b2909de Mon Sep 17 00:00:00 2001 From: Ed S Date: Thu, 18 Mar 2021 12:18:12 +0000 Subject: [PATCH] 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/rules/block-scoped-var.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/rules/block-scoped-var.md b/docs/rules/block-scoped-var.md index 97be55b889cf..9341dc5f3872 100644 --- a/docs/rules/block-scoped-var.md +++ b/docs/rules/block-scoped-var.md @@ -71,6 +71,13 @@ function doTryCatch() { f = build; } } + +function doFor() { + for (var x = 1; x < 10; x++) { + var y = f(x); + console.log(y); + } +} ``` ## Further Reading