The Event Loop

An interactive tutorial on the JavaScript event loop, from first principles: fourteen short programs traced through the call stack, microtasks and tasks.

A frontend app built by Ananda Rizki. More of them at Labs.

Labs — by Ananda Rizki

The Event Loop

Tutorial

An interactive tutorial on the JavaScript event loop, built so a beginner finishes understanding the why as well as the what. It starts from symptoms anyone has seen — a dead button, a spinner that stops spinning, text arriving in bursts — then explains why the platform has one thread at all and what a callback "arriving later" physically is. Fourteen short programs are then traced through the loop's own parts: a call stack, the microtask queue, the task queues, the animation-frame callbacks and the rendering steps, with the panel the loop is currently inside taking the accent border. They cover the stack running to empty, microtasks draining before any task, await as a microtask boundary desugared to .then, why try/catch cannot reach a later task and when an unhandled rejection is reported, what the promise combinators actually cost the loop — Promise.all as a subscription that starts nothing and answers two microtask turns after its inputs settle, the first rejection winning while the other work carries on uncancelled and unreported, and Promise.allSettled waiting for every outcome and never rejecting — rendering as work the browser queues for itself at a rendering opportunity, why a click waits behind a long task and how that becomes INP, microtask starvation, the 4 ms timer clamp, the fact that the spec says a task queue rather than the task queue, how to hand the loop back with scheduler.yield, and how Node differs. Two machine views measure the same loop against a 16.7 ms display frame and walk Node's libuv phases in the order they run since Node 20. Every lesson carries a Why panel, an in-place glossary and a Proof panel: the exact specification sentence — including the ECMAScript algorithms for PerformPromiseAll and PerformPromiseAllSettled that the tick counts are derived from — or the snippet that was run and the output it printed, in Chrome 152 and Node 24.

Built with
  • react
  • tailwind
  • motion
Related

Built by Ananda Rizki, a software engineer and designer, one of the small web apps he writes for fun.

Explore more apps on Labs