JavaScript & the runtime

JavaScript & the runtime

Why senior frontend interviews still test JavaScript itself — the event loop, closures and this, modules, collections and iterators, memory, dates and numbers, and what ES2024 to ES2026 added — and how the pages in this section fit.

Frameworks change; the language underneath them is what a senior engineer is expected to know cold. Interviewers reach for JavaScript questions because they are framework-neutral and because the answers reveal mental models: whether you can predict the order of console.logs around promises and timers, explain why a closure leaks, say what a module's live binding is, or format a currency without a library. This section is the language at the depth a senior frontend or fullstack candidate needs, pinned to the September 2026 snapshot: ES2026 was ratified in June 2026, Node 24 is the active LTS and Node 26 becomes LTS in October.

Know

  • The runtime model is small: one call stack, a heap, a task queue, a microtask queue, and a rendering step between tasks in browsers. Everything about async, timers, await ordering and responsiveness follows from it (event loop).
  • Scope is lexical and closures capture variables, not values. this is decided at the call site except for arrows, and prototypes are the object model classes sugar over (closures, scope and this).
  • Modules are static, live and singletons. ESM versus CommonJS still causes real bugs in 2026, and bundlers build on ESM semantics (modules and bundling).
  • Collections and iteration protocols are where modern JavaScript grew most: Map/Set methods, iterator helpers, generators, streams (collections, iterators and generators).
  • Memory and performance questions are about reachability, leaks from listeners and closures, and measuring before optimising (memory and performance).
  • The language keeps moving: ES2024 to ES2026 features and the ES2027 pipeline, and the Baseline vocabulary for deciding what to use unpolyfilled (modern JavaScript).
  • Dates, numbers and Intl are the practical interview trap: time zones, floating point, and formatting that must agree between server and client (dates, numbers and Intl).

How it works

A warm-up that tests four of the pages at once. Predict the output before running it:

order.ts
console.log('1 sync')

setTimeout(() => console.log('6 timeout'), 0)

Promise.resolve().then(() => console.log('3 microtask'))

queueMicrotask(() => console.log('4 microtask (queued second)'))

;(async () => {
  console.log('2 async body runs synchronously until the first await')
  await null
  console.log('5 after await: a microtask queued after the two above')
})()

// 1, 2, 3, 4, 5, 6: synchronous code first, then the whole microtask queue in order, then the timer task.
closure-and-this.ts
const counter = {
  count: 0,
  inc() { this.count++ },
  incLater() { setTimeout(() => this.count++, 0) }, // arrow: lexical this -> counter
  incBroken() { setTimeout(function () { this.count++ }, 0) }, // this is undefined in strict mode (modules)
}
const { inc } = counter
inc() // TypeError in strict mode: `this` is undefined, not counter
Gotcha· Learning APIs instead of models

Candidates memorise Promise.all versus allSettled and still cannot say why await inside a loop is slow. Interviewers probe the model, not the API surface: what is a microtask, what does a closure hold, what is a live binding. Every page in this section states the model first and the API as a consequence.

Exercise

Exercise
  • Run the ordering snippet in Node and in the browser; then add process.nextTick (Node) and a requestAnimationFrame (browser) and place them in the order.
  • Write down, without looking, the four rules for this and the six kinds of things that keep an object alive; check them against the pages.

Be able to say

Be able to say· How strong is your JavaScript outside of frameworks?

"Strong enough to explain the runtime rather than the API. I can walk through the event loop and predict ordering across timers, promises and await; explain closures, this binding and the prototype chain; describe ESM's live bindings and how bundlers rely on them; use Map, Set, iterators, generators and streams where they fit; find and fix a leak with a heap snapshot; and format dates and money with Intl so the server and the client agree. I also keep up with the language: ES2026 was ratified this June and I know what it added and what is queued for 2027."

Pages in this section

  1. 01The event loop and asyncTasks, microtasks and rendering, how await desugars, timer semantics, unhandled rejections, cancellation with AbortController, Promise combinators, breaking up long tasks, and the Node differences.
  2. 02Closures, scope, this and prototypesLexical scope and the temporal dead zone, what a closure captures and what it keeps alive, the four rules for this, arrow functions and class fields, prototypes underneath classes, private fields, descriptors, Proxy and Reflect, and equality.
  3. 03Modules and bundlingESM semantics — static structure, live bindings, singleton modules, cycles and top-level await — versus CommonJS, Node interop and package exports, tree shaking and code splitting, and what Vite and Rolldown do with all of it.
  4. 04Collections, iterators and generatorsMap, Set and their 2025 methods, WeakMap and WeakRef, the iteration protocol, generators and async iteration, iterator helpers, grouping and upsert, change-by-copy arrays, typed arrays and base64, and web streams.
  5. 05Memory and performance in JavaScriptHow garbage collection decides what lives, the leak patterns that survive it, finding retainers with heap snapshots, and the performance model — Big-O in practice, hot paths, long tasks, and measuring before optimising.
  6. 06Modern JavaScript, ES2024 to ES2026What each of the last three editions added, what is finished for ES2027, the stage 3 proposals worth knowing by name, and how Baseline, build targets and polyfills decide what you can ship unpolyfilled.
  7. 07Dates, numbers and IntlWhy Date is a trap and how to store and format time correctly across server and client, Temporal, the Intl formatters for dates, numbers, currencies, plurals, lists and relative time, floating point and money, and caching formatters.

Your notes

Open in Notes

Nothing yet. Notes filed here show up on every page of this section.