Back to library

🔁The JavaScript Event Loop

Draw the JavaScript event loop on a whiteboard from memory, then predict the output of any mixed sync/async code — and instrument a real program to prove you're right.

Applied14 drops~2-week path · 5–8 min/daytechnology

Phase 1Mapping the Event Loop

Draw the call stack, queues, and loop itself

4 drops
  1. JavaScript is single-threaded, but never alone

    6 min

    JavaScript is single-threaded, but never alone

  2. The stack is the only thing actually running

    6 min

    The stack is the only thing actually running

  3. The task queue is a waiting line, not a schedule

    6 min

    The task queue is a waiting line, not a schedule

  4. Stack, queues, loop — one sketch you'll reuse forever

    7 min

    Stack, queues, loop — one sketch you'll reuse forever

Phase 2Predicting Async Output

Predict output of setTimeout, Promise, and sync chains

5 drops
  1. Promises cut the line — every time

    6 min

    Promises cut the line — every time

  2. Walk the stack, queues, then the log

    7 min

    Walk the stack, queues, then the log

  3. async/await is promises in a costume

    7 min

    async/await is promises in a costume

  4. Chained .then() reshuffles microtask order

    7 min

    Chained .then() reshuffles microtask order

  5. Earn the trace: predict before you run

    8 min

    Earn the trace: predict before you run

Phase 3Browser vs Node in Practice

Compare browser and Node loops in real scenarios

4 drops
  1. The click handler that froze the UI

    7 min

    The click handler that froze the UI

  2. Node's loop has phases, not just queues

    8 min

    Node's loop has phases, not just queues

  3. When the same code logs different orders

    8 min

    When the same code logs different orders

  4. The microtask loop that ate the UI

    7 min

    The microtask loop that ate the UI

Phase 4Instrument Your Own Loop

Instrument a program to log each loop phase

1 drop
  1. Instrument a tiny program to log event loop phases

    15 min

    Instrument a tiny program to log event loop phases

Frequently asked questions

What is the JavaScript event loop in simple terms?
This is covered in the “The JavaScript Event Loop” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
What's the difference between the microtask queue and the task queue?
This is covered in the “The JavaScript Event Loop” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
Why does a Promise callback run before a setTimeout with zero delay?
This is covered in the “The JavaScript Event Loop” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
How is the Node.js event loop different from the browser's?
This is covered in the “The JavaScript Event Loop” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
What blocks the event loop, and how do I detect it?
This is covered in the “The JavaScript Event Loop” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.