Interview Hub
Sign in

Q6: What runs first: a `setTimeout(0)` callback or a resolved Promise `.then`?

MidAsync 29

Answer

Promise reactions (microtasks) run before the next macrotask. So after synchronous code, the microtask queue is drained, then timers/IO callbacks run. Order: sync → microtasks (Promise, queueMicrotask) → macrotasks (setTimeout, setImmediate in Node in its phase).

Having a tech or coding interview? Check 29 JavaScript & Node.js interview questions.

Source: Node.js — Event loop

EditorJavaScript · local only
What runs first: a `setTimeout(0)` callback or a resolved Promise `.then`? | TorqStudio Interview Hub