mediumDSA

Explain the Node.js event loop.

718 views
01

Understand the problem

A core concept in Node.js, this question tests understanding of its asynchronous nature.

event loopasynchronousconcurrencyarchitecture
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Stuck? AI Nudge Available

Get a conceptual hint to guide your logic without spoiling the final implementation.

03

Study the solution

The solution is waiting

Give it an honest attempt first — then compare your thinking with the full walkthrough.

04

Read the code

Ordering: sync → nextTick → Promise → timers → immediate
console.log('1 sync');
setTimeout(() => console.log('5 timeout'), 0);
setImmediate(() => console.log('6 immediate'));
Promise.resolve().then(() => console.log('4 promise'));
process.nextTick(() => console.log('3 nextTick'));
console.log('2 sync');

// 1, 2 (sync) → 3 nextTick → 4 promise (microtasks)
// → 5 timeout / 6 immediate (later phases)
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.