Overview02 / 19

How V8 executes JavaScript

From source code to processor instructions.

Consider the expression const damage = 2 + 3;. It is a short statement for a person. For the engine, it starts as a sequence of characters. The scanner recognizes tokens, the parser builds the program’s structure, and the bytecode generator turns it into executable instructions.

In V8, initial execution usually involves Ignition. Some code may later receive a machine-code version, prepared quickly by a baseline compiler or optimized more extensively.

Different functions in the same program can run in different ways. V8 might interpret one function while already having generated machine code for another. It can defer preparing functions that are not needed yet. On a later call, it can reuse code that has already been prepared.

From characters to execution

Let’s examine the main code representations in sequence.

01
Source textCurrent stage
02
TokensComing next
03
ASTComing next
04
BytecodeComing next
05
ExecutionComing next

The text describes a program in JavaScript.

1 / 5
Key takeaway

An AST describes structure; bytecode contains instructions for the Ignition interpreter; machine code contains instructions for the CPU.

Check the primary source ↗

V8 · Scanner↗The V8 team's explanation of tokenization and the path from source text to an AST.V8 · Sparkplug↗Baseline compilation from bytecode to machine code.V8 · Lazy parsing↗Why a function's full preparation can be deferred until it is called.