Event Loop

Macrotask vs Microtask

All microtasks drain before the next macrotask — always. A promise scheduled after a timer still runs first, because microtasks jump the queue.

setTimeout(f, 0) is scheduled, then Promise.resolve().then(g). g runs before f.

Microtask Q
Task Queue
setTimeout
Call Stack
Timer was first — the promise still wins

Tap the example to replay it · press and hold to slow it down

One of 40 cards in javascript flashcards. Browse every card.