Where this matters
Use this distinction when a temporary variable inside an if block shares a name with a value outside it.
let count = 1;
{ let count = 2; }
console.log(count);Read the full explanation
The inner let creates a separate block-scoped binding. It never assigns to the outer count, which remains one.
Trace the code
- The first declaration creates the outer count and stores 1.
- Entering the braces creates another count. Its value is 2, but that binding is unavailable after the block.
- The final log looks up the outer binding because it runs outside the braces.
Why the other predictions differ
2— This would require assigning to the outer count, rather than declaring a new inner binding.ReferenceError— The outer count is initialized before it is read, so it remains accessible.
1
Reading this explanation does not record mastery. A correct submitted attempt can do so, including after review.
Change one thing
Remove let from the inner statement. It now assigns to the outer binding instead of creating a new one.
Predict the result, then run this self-contained snippet in your browser’s developer console. It uses only sample values and makes no network requests.
let count = 1; { count = 2; } console.log(count);Check the variation’s output
2
Explain which binding, value, or operation changed before moving to the next challenge.