JS

runtime.js

One spine: the evolution of JavaScript

Pick an era, expand a concept, and see where it lands in today's runtimes. Every snippet can be dropped straight into the sandboxed console — the event loop panel then shows real, instrumented execution, not a looping animation.

Async Era

ES2017+2017 – 2019

`async`/`await` made the microtask queue an everyday concern. Asynchronous code finally reads top-to-bottom while still yielding to the loop at each await.

Microtasks drain completely before the next macrotask. A promise chain scheduled inside a timer still finishes before the following timer fires.

setTimeout(() => {
  console.log("timer 1");
  Promise.resolve().then(() => console.log("  micro inside timer 1"));
}, 0);

setTimeout(() => console.log("timer 2"), 0);

Promise.resolve().then(() => console.log("micro before any timer"));
console.log("sync");
Where the loop actually lives
V8Ships no event loop at all. It exposes a microtask queue and expects the embedder to pump it.
// no timers or I/O phases —
// the embedder pumps the microtask queue
Node.jslibuv phases: timers → pending → poll → check (`setImmediate`) → close. `setImmediate` fires after I/O, `setTimeout(fn, 0)` before it.
setImmediate(() => {});     // check phase: after I/O, before close
process.nextTick(() => {}); // before ANY promise microtask
DenoRust + Tokio. No `setImmediate` in the native API surface (only via the Node compatibility layer); web timers are the primitive.
await new Promise((r) => setTimeout(r, 0));
// web timers only — no setImmediate
BunCustom loop on JavaScriptCore. Implements Node's `setImmediate` for compatibility; timer latency is generally lower under load.
setImmediate(() => {}); // implemented for Node compatibility

Interview gotchas

15 genuinely tricky, well-known snippets — event-loop ordering, closures in loops, and `this`-binding traps. Open one, read the gotcha, then drop it straight into the sandboxed console to watch it really run.

Event loop
Closures & scope
this binding
Promises & async
Coercion & equality
Built-in traps