All Node.js quizzes
Advanced30 questions45 minutes

Node.js Advanced Quiz

Event loop phases, memory and GC behaviour, worker threads, diagnostics and production failure modes — the depth expected of a senior Node engineer.

Start the quiz

Sample questions from this quiz

A preview of the style and depth. Try each one, then reveal the answer — or skip straight to the timed quiz.

1. What does this print?

const fs = require('fs')
fs.readFile(__filename, () => {
  setTimeout(() => console.log('timeout'), 0)
  setImmediate(() => console.log('immediate'))
})
  • timeout then immediate
  • immediate then timeout
  • The order is non-deterministic
  • Only immediate
Show answer

Answer: immediate then timeout. Inside an I/O callback the loop is already in the poll phase, and check (setImmediate) comes immediately after poll, whereas timers only run on the next turn. So within I/O the order is deterministic — immediate first. At the top level it genuinely is non-deterministic, which is the distinction being tested.

2. Put the event loop phases in the order libuv executes them within one iteration.

  • Timers — expired setTimeout/setInterval callbacks
  • Poll — retrieve new I/O events and run their callbacks
  • Check — setImmediate callbacks
  • Close — 'close' event callbacks such as socket.on('close')
Show answer

Answer: Timers — expired setTimeout/setInterval callbacks. The full cycle is timers → pending callbacks → idle/prepare → poll → check → close. The microtask queue (promises) and `process.nextTick` drain between every phase, not as a phase of their own — which is why a recursive `nextTick` can starve the loop entirely.

3. This starves the event loop and the server stops responding. Which line is responsible?

1  function drain(queue) {
2    if (queue.length === 0) return
3    process.nextTick(() => {
4      handle(queue.shift())
5      drain(queue)
6    })
7  }
  • Line 3 — nextTick recursion drains before the loop can proceed to any phase
  • Line 4 — shift() is O(n)
  • Line 5 — recursion overflows the stack
  • Line 2 — the base case is checked too late
Show answer

Answer: Line 3 — nextTick recursion drains before the loop can proceed to any phase. The nextTick queue is drained completely between phases, so scheduling a new tick from inside a tick means the loop never advances to poll — no I/O, no timers, nothing. `setImmediate` yields to the loop between iterations and is the correct choice for this pattern. (shift() being O(n) is a real but secondary problem.)

Frequently asked questions

How many questions are in this Node.js quiz?+

30 questions, with a 45-minute time limit. Every question includes a written explanation of the correct answer.

Is this Node.js quiz free?+

Yes. Every quiz on CodexQuizz is free and needs no account. You only enter a name if you choose to post your score to the leaderboard.

What level is the advanced quiz aimed at?+

Event loop phases, memory and GC behaviour, worker threads, diagnostics and production failure modes — the depth expected of a senior Node engineer.

Can I use this to prepare for a Node.js interview?+

Yes. The questions cover the topics that come up in Node.js technical screens, and the explanations are written so that a wrong answer still teaches you the underlying concept.

Ready to test your Node.js?

30 questions, 45 minutes. Free, no sign-up.

Start now