JavaScript runs on a single thread, so it can only do one thing at a time. Synchronous code runs top to bottom on the call stack. Anything asynchronous — a setTimeout callback, a Promise .then, a click handler — does not run inline; it is placed in a queue. The event loop is the simple rule that decides what runs next: whenever the call stack is empty, it takes the next waiting task and runs it, then repeats. This tool makes that loop visible one step at a time.
The visualization shows a task queue (macrotasks) and a microtask queue. A setTimeout callback becomes a task once the timer expires. Promise reactions enter the microtask queue when the Promise settles or when .then is attached to an already settled Promise. At the end of the current task, the browser drains queued microtasks before it starts the next task. In the first preset, the Promise callback is already queued by then, so it runs before the 0 ms timer. A timer can run while a Promise is still pending.
Common questions and answers about this topic.
Because Promise callbacks are microtasks and setTimeout callbacks are macrotasks, and the event loop drains the entire microtask queue after every macrotask (and after the initial script) before it runs the next macrotask. So even a setTimeout with 0ms waits in the macrotask queue while every pending microtask runs first.
Promise reactions (.then, .catch, .finally), await continuations, queueMicrotask callbacks, and MutationObserver callbacks are microtasks. setTimeout, setInterval, requestAnimationFrame, I/O, and most DOM events are macrotasks. The distinction matters because the loop empties all microtasks between macrotasks, so microtasks can starve rendering or later timers if you schedule them endlessly.
No. A 0ms delay only means the callback is eligible to run as soon as possible, but it still goes to the macrotask queue and waits until the current synchronous code and all pending microtasks have finished. Browsers also clamp nested timeouts to a minimum (about 4ms after several levels), so 0ms is a lower bound, not an instant call.