foundation

Runtime APIs and globals

window, document, process, Buffer, timers, fetch availability, and environment-specific APIs.

Language semantics are shared; host environments differ. Browsers expose `window`, `document`, DOM, storage, and rendering APIs. Node exposes `process`, `Buffer`, `fs`, streams, and networking.

`fetch` exists in both but details differ. Accessing `window` during SSR throws. Polyfilling Node APIs in the browser bloats bundles.

Code running in workers, SSR, tests, and CLI may not share the same globals.

On interviews, explain the concept with a concrete example and name the runtime behavior interviewers probe.

Common pitfalls include mixing similar APIs and forgetting edge cases during live coding.

The trade-off is often clarity versus performance or safety versus convenience.

Checklist:

  • Separate language from host APIs.
  • Guard browser globals in SSR.
  • Test in the target runtime.