juniorJavaScript
What is hoisting in JavaScript?
Updated May 6, 2026
Short answer
Hoisting moves declarations to the top of scope before execution.
Deep explanation
Variables declared with var are initialized as undefined, while let and const remain uninitialized until execution reaches them.
Real-world example
Understanding hoisting prevents runtime reference errors.
Common mistakes
- Thinking assignments are hoisted.
Follow-up questions
- Why does let throw ReferenceError?
- Are functions hoisted?