logo

How JavaScript Runs

A high-level walkthrough of parsing, compilation, and execution phases in a JavaScript engine.

Short explanation

JavaScript execution typically involves parsing source into an AST, optionally compiling to bytecode, and executing with the engine's runtime. Modern engines mix interpretation and JIT compilation to get the best of both startup speed and runtime performance.

Mini example

// The engine parses this and builds an AST before executing
const message = 'Hello, world!';
console.log(message);

How JS handles it internally

  • Parser: turns source text into tokens and then an AST.
  • Interpreter/Baseline: executes code quickly to gather profile data.
  • JIT compiler: compiles hot functions into optimized machine code based on runtime types and behavior.

Diagram

diagram-placeholder

Related

πŸ”— Related:

FAQ

Q: Why are some functions faster after warming up?

A: Engines collect runtime type information and optimize hot code paths; after warming up, JIT-compiled code can run significantly faster.