Var Function Scope
Multiple Choice Medium
Question
Where is a var variable accessible?
Hint
var is function-scoped, not block-scoped.
Explanation
var variables are function-scoped — accessible throughout the entire function in which they are declared, not just the block. This differs from let and const which are block-scoped. This is why var can lead to unexpected behavior in loops and conditionals. Modern code prefers let/const.
Related Resources
Related Lessons
- Variables
Learn JS variables.
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.