Let Block Scope
Multiple Choice Medium
Question
In { let x = 1; } console.log(x); what happens?
Hint
let does not leak outside its block.
Explanation
let is block-scoped, meaning it only exists within the nearest enclosing curly braces. Outside the block, x is not defined, so console.log(x) throws a ReferenceError. var, by contrast, is function-scoped and would leak out of the block (but not the function).
Related Resources
Related Lessons
- Scope and Visibility
Learn about scope.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.