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

















