Interview Q&A / Node.js

IntermediateQuick answer1 min readUpdated 3 Oct 2026

Predict the output: setTimeout, a promise, process.nextTick and plain logs together

SHORT ANSWER

Synchronous code runs first, then process.nextTick callbacks, then promise callbacks (microtasks), then timers. So the order is sync, nextTick, promise, setTimeout.

Explain it simply

Picture a railway counter. The person at the window finishes the current customer completely (synchronous code). Before calling the next customer from the queue, they clear two small priority slips: first the nextTick slip, then the promise slip. Only then do they call the next ordinary customer, which is a timer or I/O callback.

Example

js
console.log("A");

setTimeout(() => console.log("B: timeout"), 0);

Promise.resolve().then(() => console.log("C: promise"));

process.nextTick(() => console.log("D: nextTick"));

console.log("E");

// prints:
// A
// E
// D: nextTick
// C: promise
// B: timeout

Step by step:

  1. A and E are synchronous, so they print first.
  2. When the main script ends, Node drains the nextTick queue, so D prints.
  3. Then the promise microtask queue drains, so C prints.
  4. The event loop then reaches the timers phase and B prints.

In an ES module file the order of D and C can differ, because the module itself runs inside a promise job. That is why most examples use CommonJS.

What to say in the interview

"Sync code first, then the nextTick queue, then promise microtasks, then the event loop phases where timers run. nextTick has higher priority than promises in CommonJS."

Common mistakes

  • Thinking setTimeout(fn, 0) runs immediately.
  • Starving the loop with recursive nextTick calls, which blocks I/O.

#nodejs#event-loop#async

Related questions

Practise more Node.js questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Node.js quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.