Hoisting Demo

Easy
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Hoisting Demo

Approach

Contrast function hoisting (fully hoisted and callable before declaration), var hoisting (declaration hoisted but value is undefined), and let/const temporal dead zone (not accessible before declaration). Loop scoping highlights var leaking into outer scope versus let being block-scoped.

Complexity Analysis

Time
O(1)
Space
O(1)

Pattern

Hoisting and TDZ

Why It Works

JavaScript hoists declarations during the compile phase. Function declarations are fully initialized, var is initialized to undefined, and let/const remain uninitialized until execution reaches the declaration.

Updated Feb 2026