Can an inner block see a let variable from an outer block in JavaScript?
Yes. Inner blocks can access outer block-scoped variables via the scope chain. But outer blocks cannot see inner block-scoped variables. This is the same as function scope nesting.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Block Scope with let and const: Examples
Variables declared with let and const are only accessible inside the nearest pair of braces. This applies to if blocks, for loops, try/catch, and plain blocks. var is not block-scoped and leaks out.
Yes. Each iteration of for...of creates a fresh binding, and the loop variable does not change within an iteration. Use const for for...of and for...in. Use let only for classic for loops where the counter increments.
No. let is block-scoped, so the loop variable stays inside the loop. var is function-scoped and leaks out, which is one reason to prefer let in loops.
Still have questions?
Browse all our FAQs or reach out to our support team
