JavaScriptEasy
JavaScript Hoisting — var, let, const & Function Hoisting Explained
Hoisting is JavaScript's default behavior of moving declarations to the top of their scope before code execution. Understanding hoisting helps you predict how variables and functions behave before they're defined in your code.
6 concepts·2 practice problems·Beginner level
Key Concepts
- •Variable declarations (var) are hoisted, but not their assignments
- •Function declarations are fully hoisted (name + body)
- •let and const are hoisted but stay in the "Temporal Dead Zone" until declared
- •Function expressions are NOT hoisted like function declarations
Topics Covered
HoistingHow JS moves declarations to the topVariable Hoisting: var vs let vs constHow var, let, and const are hoisted differentlyFunction Hoisting: Declarations vs ExpressionsWhy function declarations can be called before definitionTemporal Dead Zone (TDZ) ExplainedWhy you cannot access let/const before declarationScope Basics: Global, Function & BlockWhere variables live and are accessibleLexical Scoping & Scope ChainScope is determined at write time, not runtime
Practice Problems
Common Mistakes to Avoid
- ×Assuming let/const don't hoist (they do, but have TDZ)
- ×Using var in loops and expecting block scope
- ×Relying on hoisting instead of declaring variables at the top
Interview Tips
- ✓Explain the difference between declaration and initialization
- ✓Know what TDZ means and when it applies
- ✓Be able to predict output of hoisting quiz questions