JavaScript · Event Loop · Senior · Comparison
How does Node.js's event loop model differ from the browser's?
Short Interview Answer
Node uses a phased loop (timers, pending, poll, check, close) with `nextTick` and microtasks; browsers focus on tasks, microtasks, and rendering.
Detailed Explanation
Node's libuv-driven loop has phases: timers (`setTimeout`/`setInterval`), pending callbacks, idle/prepare, poll (I/O), check (`setImmediate`), close callbacks. `process.nextTick` queues run after the current operation before other microtasks in Node's historically specific ordering (promise thenables interact carefully). Browsers don't expose `setImmediate` (historically) and prioritize rendering/input. Both share the microtask concept for promises. When writing isomorphic code, avoid relying on Node-only ordering. Workers exist in both environments with their own loops.
Interview Tip
Don't recite every phase unless asked — summarize and offer depth.
Common Mistake
Claiming browser and Node event loops are identical in ordering guarantees.