When do plain code, Promise.then and setTimeout run?
Answer out loud or in your head first, then compare.
Answer
First the current synchronous code finishes. Reactions to settled Promises go to the so-called microtask queue, which is processed before many other kinds of work. A timer can be handled only after its time has passed and when the environment gets a chance.
In the simple example console.log('A'); Promise.resolve().then(() => console.log('B')); setTimeout(() => console.log('C'), 0) we see A, then B and C. A zero delay on a timer doesn't mean “immediately”. For Node's extra mechanisms, such as nextTick and setImmediate, you need to take the context and version into account. Without that, don't recite one order for every program.
Why it matters: A classic fundamentals question and a source of bugs in timing tests.
Possible follow-ups: Why can many microtasks delay handling the network?
How did it go? Be honest — “Not yet” puts the question on your review list.
Start with
- B-P03 · What is the event loop? — JavaScript, TypeScript and Node.js
- B-P04 · What is a Promise? — JavaScript, TypeScript and Node.js
Related questions
- Order: synchronous code, Promise.then and setTimeout — JavaScript, TypeScript and Node.js
Further reading
- Node.js: The Event Loop(opens in a new tab)Docs; accessed 22.10.2026. Event loop phases, timers and differences between Node/libuv versions.