Chapter XI · The JavaScript Runtime

What Happens When JavaScript Runs?

When a JavaScript file runs, the engine parses the code, generates an Abstract Syntax Tree (AST), compiles it into bytecode, and executes it within an execution environment.

01 How It Works

Think of a factory assembly line where raw design blueprints are parsed, translated into machine tasks, and processed piece by piece.

The environment allocates memory via the heap and orchestrates execution tracking via the call stack, coordinating asynchronous hooks through the runtime system.

example.js
console.log("Start");
let x = 5 + 5;
console.log(x);
  1. 1. Source code is loaded and parsed into an AST.

  2. 2. Ignition interpreter compiles AST into bytecode and executes it.

  3. 3. TurboFan optimizing compiler JIT-optimizes hot code paths during runtime.

02 Practical Example

Here is how you might see this concept applied in real-world code:

practical.js
// Engine reads top-to-bottom, builds execution contexts, and evaluates expressions.
const a = 10;
const b = 20;
console.log(a + b);

Key Takeaway

JavaScript execution involves parsing, bytecode compilation, memory allocation, and sequential stack processing.

Related Concepts