yoklainterview sim

Backend Nodejs Event Loop Async Interview Questions

75 verified Backend Nodejs Event Loop Async interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Nodejs Event Loop AsyncDifficulty 1
console.log("A");
console.log("B");
console.log("C");

What does this print, and why can you be sure of the order?
  • a"A", "B", "C"
  • bThe order isn't guaranteed, since each console.log is scheduled as a separate task
  • c"C", "B", "A" — Node evaluates statements in reverse order because of hoisting
  • dIt depends on which event loop phase is active when the script starts running
Explanation:There is no asynchronous operation here at all. Node executes synchronous statements one at a time, in source order, on a single JavaScript thread. Nothing defers console.log("B") or console.log("C"), so the output is always "A", "B", "C".
Nodejs Event Loop AsyncDifficulty 2
What is the Node.js event loop responsible for?
  • aCompiling JavaScript source into machine code before execution begins
  • bManaging a pool of OS threads that each run one callback concurrently
  • cChecking whether the call stack is empty, and if so, moving the next queued callback onto it
  • dAllocating and freeing memory for objects on the V8 heap
Explanation:The event loop is the mechanism that lets single-threaded JavaScript handle asynchronous work: it repeatedly checks if the call stack is empty, and when it is, it pulls the next ready callback (from a timer, I/O completion, microtask queue, etc.) onto the stack to execute. It has nothing to do with compilation or memory management directly.
Nodejs Event Loop AsyncDifficulty 1
console.log("start");
setTimeout(() => {
  console.log("timeout");
}, 0);
console.log("end");

What does this print?
  • a"start", "timeout", "end"
  • b"start", "end", "timeout"
  • c"timeout", "start", "end"
  • dIt throws an error because setTimeout requires a positive delay greater than 0
Explanation:setTimeout(fn, 0) doesn't run fn immediately — it schedules it to run in a later phase of the event loop, after the current synchronous code finishes. So "start" and "end" print first (synchronously), and "timeout" prints afterward, once the event loop reaches the timers phase.
Nodejs Event Loop AsyncDifficulty 1
How many threads does Node.js use to run your JavaScript code by default?
  • aOne thread per open socket connection
  • bA pool of 4 threads that grows with the number of setTimeout calls
  • cA separate thread for every asynchronous callback
  • dA single thread, though libuv may use extra threads behind the scenes for some OS-level operations
Explanation:Your JavaScript code always runs on one main thread. That's why a long synchronous computation blocks everything else. Node (via libuv) does use additional threads internally for some things, but your JS callbacks themselves execute one at a time on that single thread.
Nodejs Event Loop AsyncDifficulty 2
setTimeout(() => console.log("first"), 100);
setTimeout(() => console.log("second"), 10);

What gets logged, and in what order?
  • a"first" then "second", in registration order
  • bIt throws, because two setTimeout calls can't share the same phase
  • c"second" then "first"
  • dBoth callbacks run at exactly the same moment, so the order is random
Explanation:Each timer becomes eligible to run once its delay has elapsed. The 10ms timer's threshold passes before the 100ms one, so its callback runs first regardless of the order the two setTimeout calls appear in the source code.
Nodejs Event Loop AsyncDifficulty 1
console.log("1");
Promise.resolve().then(() => console.log("2"));
console.log("3");

What does this print?
  • a"1", "3", "2"
  • b"1", "2", "3"
  • c"2", "1", "3"
  • dIt throws because Promise.resolve() must be called with an argument
Explanation:Promise.resolve() creates an already-resolved promise, but its .then callback is still scheduled as a microtask, not run inline. Microtasks only run once the current synchronous block finishes, so "1" and "3" print first, then "2".

Test yourself against the 3300-question Backend bank.

Start interview