Event Loop

Macrotask vs microtask

Both queues are first in, first out, but all microtasks drain before the next macrotask — always. A promise scheduled after a timer still runs first.

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

Microtask queue
Task queue
setTimeout
Call stack
Timer was first: the promise still wins

One of 40 cards in the JavaScript deck. Browse every card.