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.

A rejected promise with no `.catch` or `await` triggers `unhandledrejection`. The timing is subtle: a handler attached in the *same task* still saves it — the report only fires after the microtask queue drains with the promise still unhandled.

// Rescued within the same task: no unhandledrejection fires.
Promise.reject(new Error("rescued in same task"))
  .catch((err) => console.log("caught:", err.message));

// Handler attached in a later macrotask — too late to prevent the report.
const late = Promise.reject(new Error("late handler"));
setTimeout(() => late.catch(() => console.log("late rescue ran")), 0);

// Never handled at all — reported as an uncaught (in promise) error.
Promise.reject(new Error("never handled"));

console.log("sync done");
What happens when you drop a rejection
V8The engine only fires the host's `unhandledrejection` mechanism after the microtask queue drains — a handler attached in the same task still rescues it.
Node.jsSince Node 15 the default `--unhandled-rejections=throw` makes an unhandled rejection crash the process; `warn`, `strict`, and `none` are the other modes.
DenoPrompts on the first unhandled rejection so you can inspect, ignore, or exit — use `--no-prompt` to fail fast in CI.
BunPrints `Uncaught (in promise) …` and exits with a non-zero status by default, like Node in strict mode.

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