Skip to content
jshacks.dev
Fundamentals

What Is a JavaScript Engine and How V8 Compares to Others

A JavaScript engine parses and runs your code. V8, SpiderMonkey and JavaScriptCore follow one standard but differ in stack traces, flags and shipping dates.

8 min read
Summarize in AI
Flat illustration of an editor window full of code, with the JavaScript, Node.js and Vite logos.

When you run a JavaScript file, something has to read the text and make the computer do what it says. That something is the engine, and there are only a few in wide use, which is why a sentence like "this works in Chrome and breaks in Safari" has a real explanation. The engines are built by different teams with different priorities, and they implement one standard, so almost all code behaves identically, and the differences are concentrated in places you can name: the timing of new features, the format of error messages, the non-standard extras and the performance profile. This post explains what an engine does, introduces the three that matter, shows a few differences you can observe from code on Node.js 24, and ends on the habits that keep your programs portable. The split between engine, language and host is explained in the post on JavaScript and ECMAScript, and the machinery that runs callbacks is covered in the post on how JavaScript runs.

What an engine does

An engine has four jobs. It parses source text into a tree, reporting syntax errors before anything runs. It compiles that tree into bytecode and, for hot code, into machine code. It executes the result with the language's semantics and provides the built-in objects. And it manages memory, allocating objects and freeing the ones nothing can reach, as covered in the post on garbage collection.

JavaScript
const source = "const total = [1, 2, 3].reduce((sum, n) => sum + n, 0); total * 2";

console.log(eval(source));

const fn = new Function("a", "b", "return a * b + 1");
console.log(fn(6, 7), fn.length, fn.name);
console.log(fn.toString());

try {
  new Function("const = 1");
} catch (error) {
  console.log(error.name);
}

console.log(typeof process.versions.v8, Object.keys(process.versions).includes("v8"));
Text
12
43 2 anonymous
function anonymous(a,b
) {
return a * b + 1
}
SyntaxError
string true

The parse step ran first: the syntax error in the last Function was reported when the function was created, before any of its code could run. Function.prototype.toString() returns the source text, which the engine keeps, and the standard requires that it returns the exact characters written. And Node.js exposes the engine's version, because Node.js embeds V8, so a Node.js release implies a V8 release and with it a set of language features.

From interpreter to optimizing compiler

Modern engines do not choose between interpreting and compiling. They start by running bytecode in an interpreter, which begins fast and runs slowly, collect information about which code runs often and which types it sees, and compile the hot parts to optimized machine code with a JIT compiler that compiles at run time. If an assumption that the optimized code made turns out false, such as a function that always saw numbers suddenly receiving a string, the engine discards the optimized version and falls back.

This is why the same function can run at different speeds during one program, and why microbenchmarks mislead: a loop timed once measures the interpreter, and a loop timed after warm-up measures the optimized code. It is also why consistent types help: a function that sees one shape of object and one kind of argument is easy to optimize, and one that sees many is not.

JavaScript
function add(a, b) {
  return a + b;
}

const results = [];
for (let i = 0; i < 5; i++) results.push(add(i, 1));
results.push(add("a", "b"));
results.push(add(1.5, 2.5));
results.push(add(10n, 5n));

console.log(results);
Text
[
  1, 2,    3, 4,
  5, 'ab', 4, 15n
]

The function handled integers, strings, floats and bigints with the same source, and the engine tracks which it sees. You cannot observe the tiers from the program, and that is by design: the language guarantees the same result whichever tier runs, and the engine is free to optimize as it likes. We would not rewrite code for a specific engine's optimizer without a profile that shows the cost.

The three main engines

Each engine is a large project with its own history, and each is embedded in several products.

EngineDeveloped byUsed in
V8GoogleChrome, Edge, Opera, Node.js, Deno, Electron
SpiderMonkeyMozillaFirefox
JavaScriptCoreAppleSafari, Bun, WebKit-based apps

Beyond these, there are engines built for other constraints. Hermes is an engine for React Native that favors startup time and memory, QuickJS is a small embeddable engine, and Rhino and GraalJS run on the Java platform. They matter if you target their environments, and for browser and server work the three above cover nearly everything. Engines are tracked against the same standard: because a feature can only enter the language when two or more of them ship it, as described in the post on TC39, the major engines have to agree before a feature becomes standard.

Conformance: test262

The shared test suite for the language is called test262, maintained alongside the specification. Each feature has tests, and every engine reports its pass rate. A feature that passes everywhere behaves identically, and the differences you meet are in what the suite does not cover: things the specification leaves to the implementation.

JavaScript
const checks = {
  "Array.prototype.at": typeof [].at,
  "Object.groupBy": typeof Object.groupBy,
  "Promise.withResolvers": typeof Promise.withResolvers,
  "Set.prototype.union": typeof new Set().union,
  "Array.fromAsync": typeof Array.fromAsync,
  "RegExp.escape": typeof RegExp.escape,
  "Temporal": typeof globalThis.Temporal,
  "using (Symbol.dispose)": typeof Symbol.dispose,
};

for (const [feature, type] of Object.entries(checks)) {
  console.log(feature.padEnd(26), type);
}
Text
Array.prototype.at         function
Object.groupBy             function
Promise.withResolvers      function
Set.prototype.union        function
Array.fromAsync            function
RegExp.escape              function
Temporal                   undefined
using (Symbol.dispose)     symbol

On this Node.js 24.1, which embeds V8, most recent features are present, and Temporal is not enabled by default. Another engine at another version would give a different table, which is the point: use detection like this, with typeof, to ask what a runtime supports, and do not infer it from the engine's name. The posts on ES2025 and ES2026 list the features by edition.

Differences you can observe

Three areas differ in ways a program can see. The first is the format of error stack traces, which the standard does not define.

JavaScript
function inner() {
  throw new Error("boom");
}

function outer() {
  inner();
}

try {
  outer();
} catch (error) {
  const lines = error.stack.split("\n");
  console.log(lines[0]);
  console.log(lines[1].trim().startsWith("at inner"));
  console.log(typeof error.stack, error.stack.includes("outer"));
}

console.log(typeof Error.captureStackTrace, typeof Error.stackTraceLimit);
console.log(Error.stackTraceLimit);
Text
Error: boom
true
string true
function number
10

In V8, a stack trace begins with the error name and message, then one line per frame that starts with at. SpiderMonkey and JavaScriptCore use a different layout, with function@file:line:column on each line, and the Error.captureStackTrace and Error.stackTraceLimit properties exist only in V8. Code that parses stack traces, such as error-reporting tools, has a parser per engine, and code that wants a clean trace in V8 can call captureStackTrace. A standard property for this does not exist yet.

The second area is message text. The wording of a TypeError for reading a property of undefined differs between engines, so code must never compare messages, and a test that asserts on message text breaks when the runtime changes.

JavaScript
const failures = [
  () => null.property,
  () => undefined(),
  () => new (class A { constructor() { this.x; } })().missing.deeper,
  () => JSON.parse("{"),
];

for (const run of failures) {
  try {
    run();
  } catch (error) {
    console.log(error.name.padEnd(12), error.message);
  }
}
Text
TypeError    Cannot read properties of null (reading 'property')
TypeError    undefined is not a function
TypeError    Cannot read properties of undefined (reading 'deeper')
SyntaxError  Expected property name or '}' in JSON at position 1 (line 1 column 2)

These messages come from V8. Firefox and Safari word the same failures differently, such as "can't access property" or "undefined is not a function", and the exact JSON parse message varies by version as well. Branch on error.name and the type, and use error.code where the host provides one.

The third area is timing. A feature moves from proposal to engine to stable release at different times in each engine, and the order is not fixed. One browser may ship a feature a year before another, and Node.js picks it up when it updates V8. Check a compatibility table for the engines you target, and see the detection pattern above.

Flags and extras

Engines accept flags that enable experimental features or change behavior, and expose non-standard extensions. V8's flags are visible through Node.js.

JavaScript
import v8 from "node:v8";

console.log(typeof v8.getHeapStatistics().total_heap_size);
console.log(typeof globalThis.WebAssembly, typeof globalThis.SharedArrayBuffer);
console.log(typeof globalThis.gc);

const nonStandard = ["__defineGetter__", "__lookupGetter__"].map(
  (name) => typeof Object.prototype[name],
);
console.log(nonStandard);
Text
number
object function
undefined
[ 'function', 'function' ]

A runtime flag like --harmony-temporal, used in the post on Temporal, turns on a feature the engine has implemented but not released. WebAssembly and SharedArrayBuffer are host-provided APIs available in these engines, and gc is absent without --expose-gc. The legacy __defineGetter__ helpers are non-standard in origin and standardized later for compatibility, which shows how an extension can become part of the language. A flag is a tool for experiments and diagnostics, and a production program should not depend on one.

Choosing, if you choose

Most developers do not choose an engine: the browser they target and the server runtime they pick decide it. For servers, Node.js and Deno use V8, and Bun uses JavaScriptCore, which has a different startup and memory profile. Performance claims comparing them depend on the workload, the version and the hardware, and published numbers age within months, so measure your own workload before switching, and treat compatibility with your dependencies as the larger factor.

The practical rule is portability: write to the standard, detect features instead of engines, avoid non-standard extensions in shared code, and test in every engine you ship to. A test matrix with Chromium, Firefox and WebKit, as Playwright provides, covers the browser side in one run.

Where this model stops

The picture of "an engine runs your code" leaves out the host: timers, the network, the DOM and the event loop come from the runtime and not the engine, so two runtimes on the same engine can differ widely, as Node.js and Deno do. And the engines are moving targets: a limit or an optimization noted in one release may not hold in the next, so treat any engine-specific advice as dated and verify it on the version you use.

The language that all engines implement is defined in ECMA-262, the shared tests live in the test262 repository, and the V8 project documents its own work on v8.dev.

Taggedbeginner
Share

Keep reading

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.