Var Hoisting Behavior
Multiple Choice Medium
Question
What does console.log(x); var x = 1; print?
Hint
var is hoisted but its assignment is not.
Explanation
var x is hoisted to the top of the scope, so the variable exists but is undefined until the assignment line executes. console.log(x) runs before the assignment, so it prints undefined. With let or const, this would throw a ReferenceError due to the temporal dead zone.
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.