liveBook · Manning

JavaScript runtime

As explained in Secrets of the JavaScript Ninja, Third Edition

A software environment that executes JavaScript and provides access to host-platform features.

A JavaScript runtime is the environment that executes JavaScript and connects it to its host platform. It includes an engine that turns code into machine instructions and API bindings that let code use host features. section 1.1.1

The host environment determines which capabilities are available:

  • Browsers provide APIs for network requests, user events, and DOM updates. section 1.1.1
  • Node.js provides APIs for TCP sockets, disk logging, and subprocesses. section 1.1.1
  • Runtimes use different engines: V8 powers Chrome and Node.js; JavaScriptCore powers Safari and Bun. section 1.1.1

Code may target one runtime or many. Libraries such as Lodash are used across browsers, servers, and apps, while tools such as jsdom can simulate a browser-like environment in Node.js. Runtime differences matter because feature support varies. section 1.1.1 section 1.1.2

Supporting newer JavaScript features

When a target runtime lacks a feature, transpilation can transform syntax to an older ECMAScript standard, while a polyfill can supply a missing feature. Neither guarantees support for every feature: unsupported regex lookbehind, for example, can still fail. Check target runtimes and test against them. section 1.1.3

Figure 1.1 How a JavaScript runtime brings JavaScript code to life.

Use the figure to visualize how a runtime brings JavaScript code to execution. section 1.1.1

How Secrets of the JavaScript Ninja, Third Edition covers it

How deep it goes
Traces execution through engines and API bindings, then addresses feature support and compatibility workarounds.
Examples
Uses browser APIs, Node.js APIs, V8, JavaScriptCore, Lodash, and jsdom as examples.
What you can do after
Evaluate runtime compatibility by checking feature support and choosing transpilation, polyfills, or runtime tests.
How it connects
Connects runtimes to JavaScript engines, ECMAScript feature support, transpilers, and polyfills.

Also explained in

Compare how 6 books explain JavaScript runtime →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Third Edition. The section links point to the parts of the book it draws on.