JavaScript Event Loop Explained — Call Stack, Task Queue, Microtasks
Fast recall
Quick revision
Core answer
Single-threaded execution model, call stack, macrotask queue, microtask queue, render steps; how promises/queueMicrotask jump the macrotask queue
Confusing microtasks (promise callbacks, queueMicrotask) with macrotasks (setTimeout, setInterval, I/O)
Walk through a full loop tick: run one macrotask → drain ALL microtasks → render → next macrotask; mention process.nextTick (Node) sits above all microtasks
Interview-ready guide
Interview answer
Open (15–20 seconds): Restate the question and give the one-sentence definition.
Body (45–60 seconds): Walk through Single-threaded execution model, call stack, macrotask queue, microtask queue, render steps; how promises/queueMicrotask jump the macrotask queue as a story: what runs, what breaks, what you log/measure.
Pitfall (15 seconds): Call out Confusing microtasks (promise callbacks, queueMicrotask) with macrotasks (setTimeout, setInterval, I/O) — interviewers reward honesty about real bugs.
Finish (15–20 seconds): Add Walk through a full loop tick: run one macrotask → drain ALL microtasks → render → next macrotask; mention process.nextTick (Node) sits above all microtasks, then offer a trade-off question back (“do you optimize for TTFB or TTI here?”).
JavaScript Event Loop Explained — Call Stack, Task Queue, Microtasks
Direct Answer
How does the JavaScript event loop work? Explain call stack, task queue, and microtask queue.
In one line: name the mechanism, where it applies (the type checker, emit pipeline, and how types line up with runtime JS), and the user-visible outcome.
Interviewers dig into: Single-threaded execution model, call stack, macrotask queue, microtask queue, render steps; how promises/queueMicrotask jump the macrotask queue.
Classic weak answer: Confusing microtasks (promise callbacks, queueMicrotask) with macrotasks (setTimeout, setInterval, I/O).
Senior finish: Walk through a full loop tick: run one macrotask → drain ALL microtasks → render → next macrotask; mention process.nextTick (Node) sits above all microtasks.
Common Mistakes & Pitfalls
Confusing microtasks (promise callbacks, queueMicrotask) with macrotasks (setTimeout, setInterval, I/O)
Check your understanding
Answer these without looking back at the article.
- What is the difference between microtasks and macrotasks?
- Does the browser event loop differ from Node.js?
- Why does Promise.resolve().then() run before setTimeout(0)?
- What is queueMicrotask?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.