How JavaScript Engines Work

A JavaScript engine parses JavaScript source, compiles it to bytecode and then to machine code, and executes it. The three major engines, V8, SpiderMonkey, and JavaScriptCore, are written mainly in C++ (SpiderMonkey also uses Rust). JavaScript the language is defined by the ECMAScript standard; the engines are the implementations.

The language vs the engine

"What is JavaScript written in?" is really two questions. JavaScript itself is a specification, ECMAScript, standardized by TC39, so the language is not "written in" anything. What is written in a concrete language is the engine that runs JavaScript, and the performance-critical parts of every major engine are written in C++.

The execution pipeline

Modern engines do not simply interpret source line by line. They run a multi-stage pipeline:

All of this needs precise control over memory layout and machine code, which is why these engines are written in C++ rather than in a managed language.

V8 (Chrome, Node.js, Deno)

V8 is Google's open-source JavaScript and WebAssembly engine, written in C++. It powers Chrome, Node.js, Electron, and Deno. Note that the runtimes built on top differ in language: Node.js wraps V8 in C++ and JavaScript, while Deno wraps the same V8 engine in Rust.

SpiderMonkey (Firefox)

SpiderMonkey is Mozilla's engine and the first JavaScript engine ever built, written by Brendan Eich in 1995 alongside the language itself. It is written in C++ with a growing amount of Rust, and powers Firefox.

JavaScriptCore (Safari, Bun)

JavaScriptCore (also called Nitro) is Apple's engine, written in C++, with a four-tier JIT. It powers Safari and every browser on iOS, and it is also the engine inside Bun, a runtime whose own code is written in Zig.

Explore JavaScript Relationships in Graph →