The examples
In curriculum order — each one asks for your prediction first, then animates exactly why. Warm-ups build the model, core examples are the interview classics, advanced ones break the loop on purpose — including Node, where the same language runs on a different loop.
- Fig. 1warm-up
One thing at a time
No async at all — how the stack really runs your code.
7 steps · predict first →
- Fig. 2warm-up
setTimeout(0), alone
Zero milliseconds does not mean now.
7 steps · predict first →
- Fig. 3warm-up
A promise, alone
Even an already-resolved promise waits its turn.
6 steps · predict first →
- Fig. 4core
Promise vs setTimeout
The classic showdown — and the classic interview question.
9 steps · predict first →
- Fig. 5core
.then after .then
Each link in a .then chain is its own microtask.
7 steps · predict first →
- Fig. 6core
setTimeout inside a for loop
Why it logs 3, 3, 3 — a closure bug and a timing bug at once.
11 steps · predict first →
- Fig. 7core
async/await, unmasked
Watch a function leave the stack mid-body.
7 steps · predict first →
- Fig. 8core
Promise.all — waiting in parallel
Two waits, one wait's worth of time — if you start them first.
9 steps · predict first →
- Fig. 9core
fetch — a real network wait
A real network round trip, and the thread never waits.
9 steps · predict first →
- Fig. 10core
Clicks are just tasks
Your click handler queues behind everything else.
8 steps · predict first →
- Fig. 11advanced
The checkpoint runs between every task
Microtasks drain after every task — not once at the end.
10 steps · predict first →
- Fig. 12advanced
Starving the loop
VIPs forever — the timer never eats.
8 steps · predict first →
- Fig. 13advanced
requestAnimationFrame vs setTimeout
The render step: neither a task nor a microtask.
10 steps · predict first →
- Fig. 14advanced
Blocking the loop
One hot loop freezes the whole page.
6 steps · predict first →
- Fig. 15advanced
Node: nextTick, promises, timers, immediate
Same language, different loop: libuv phases and nextTick.
11 steps · predict first →