How JavaScript Engines Work
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:
- Parser: turns source text into an abstract syntax tree (AST).
- Bytecode compiler + interpreter: lowers the AST to bytecode and starts executing it immediately, so code runs without waiting for full optimization. In V8 this interpreter is called Ignition.
- Optimizing JIT: the engine watches which functions run often ("hot" code) and recompiles them to optimized machine code, speculating on the types it has observed. V8 uses TurboFan and Maglev; if a type assumption turns out wrong, the engine "deoptimizes" back to bytecode.
- Garbage collector: reclaims unused memory in the background.
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 →