Local vs Global Scope Quiz
Question
What happens when you try to access a let variable outside its function?
Hint
Variables declared inside a function are local to that function.
Explanation
Variables declared with let (or const or var) inside a function are local to that function. They cannot be accessed from outside. Attempting to reference them throws a ReferenceError. This is called function scope — the variable only exists within the function that declares it.
Related Resources
Related Lessons
- Scope and Visibility
Learn about scope and variable visibility.
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.