Watch it run
Pick a snippet, then play it or step through. Every step says what just happened.
console.log("start");setTimeout(() => { console.log("timeout");}, 0);console.log("end");Call stack
What is running right now
Web APIs / timers
Waiting outside JavaScript
Task queue
Macrotasks: one per turn
Microtask queue
Drained fully after each task
Console output0 lines
Nothing has run yet. The stack is empty and both queues are empty.
Try it yourself
Change the code, predict the order, then run it for real in your browser.
Press Run to see what your code prints, in order.
Runs in this browser, in an isolated frame with no access to this page. console.log, info, warn and error are shown; code runs as a classic script, so use an async function for await.
Check yourself
3 questions. Get them all right to finish this topic.
0 of 3 right so far. Get all three to finish this topic.
Browser or Node: what changes?
- All three snippets print in the same order in Chrome and in Node 22, whether Node runs them as CommonJS or as an ES module. The task-then-microtasks rule is the same in both.
- Node has no screen to paint. Its loop goes through phases instead (timers, I/O polling, setImmediate callbacks, close callbacks), covered in Node's event loop.
- Node adds
process.nextTick, whose queue runs before promise microtasks. Browsers have no equivalent. - A 0 ms timer is never instant. Node treats it as 1 ms; browsers clamp deeply nested timers to at least 4 ms and slow timers down in background tabs.