From 909c7271b8d294bd884827ad5df02615b6ec5e82 Mon Sep 17 00:00:00 2001 From: Ed S Date: Thu, 25 Mar 2021 00:19:55 +0000 Subject: [PATCH] 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 --- docs/rules/block-scoped-var.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/rules/block-scoped-var.md b/docs/rules/block-scoped-var.md index 97be55b889c..75c7db02580 100644 --- a/docs/rules/block-scoped-var.md +++ b/docs/rules/block-scoped-var.md @@ -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: @@ -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