liveBook · Manning

JavaScript

As explained in JavaScript in Depth

A high-level, dynamically typed programming language standardized as ECMAScript and commonly used for web development and other runtime environments.

JavaScript is standardized as ECMAScript, but observed behavior also depends on the JavaScript engine and host runtime. Treating those layers as interchangeable makes asynchronous code, modules, and APIs surprisingly difficult to predict. section 1.3.3 section 1.1

Analyze JavaScript behavior by separating three kinds of responsibility:

  • Language-defined behavior, including promises, should be implemented consistently across runtimes. section 1.3.3
  • Implementation-defined behavior follows the JavaScript engine and may be shared by runtimes using that engine. section 1.3.3
  • Host-defined behavior belongs to a particular runtime; Node.js process.nextTick() and its nextTick queue are examples. section 1.3.3
  • Module interpretation also matters: Node.js loads CommonJS and ECMAScript Modules differently, with plain .js files defaulting to CommonJS there. section 1.1
Listing 1.1 A friendly puzzle
function print(a) {
  process.stdout.write(a);
}
 
queueMicrotask(() => print('e'));
process.nextTick(() => print('H'));
setTimeout(() => print('l'), 0);
Promise.resolve().then(() => print('l'));
setImmediate(() => print('o\n'));

Use the asynchronous puzzle to predict execution order, then account for process.nextTick(), microtasks, promises, timers, immediates, module interpretation, and runtime-specific scheduling. section 1.1

Identical source, different output

The same scheduling puzzle prints Hello in Node.js CommonJS, elHo followed by l in Node.js ECMAScript Modules, elHlo in Deno, Helo followed by l in Bun, and different results or errors in browser and worker environments. The variation reflects host scheduling, available globals, and module loading rather than a single universal execution order. section 1.1 section 1.3.3

How JavaScript in Depth covers it

How deep it goes
Explains scheduling and runtime boundaries through runnable puzzles, but defers detailed treatment of types, promises, streams, garbage collection, and diagnostics.
Examples
Uses a hello-output puzzle across Node.js, Deno, Bun, Chrome, and Cloudflare Workers.
What it assumes
Assumes basic JavaScript familiarity while teaching language, engine, and host distinctions from the beginning.
What you can do after
Diagnose/debug with runtime comparisons and execution-order reasoning instead of assuming source order determines output.
How it connects
Connects ECMAScript, JavaScript engines, host runtimes, promises, CommonJS, and ECMAScript Modules.

Also explained in

Compare how 18 books explain JavaScript →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of JavaScript in Depth. The section links point to the parts of the book it draws on.