Course contentsShow
← JavaScript
Lesson 14 of 2,7231. JavaScript FoundationsFree lesson

Interpretation vs Compilation

Early engines interpreted code line-by-line; modern engines use Just-In-Time (JIT) compilation for speed.

Interpretation vs Compilation

You'll learn: How JavaScript engines have evolved from interpreting code line-by-line to using Just-In-Time compilation for better performance.

Two Ways to Run Code

When a JavaScript engine receives your code (after parsing it into an AST, as you learned), it needs to execute it. Historically, there were two main approaches:

Interpretation

Interpretation means reading and executing code line-by-line, on the fly. Think of it like a live translator at a conference who translates each sentence as the speaker says it.

Pros: Start running immediately
Cons: Slower execution, especially for repeated code

Early JavaScript engines (like the first versions of SpiderMonkey) worked this way. They'd read your code, convert each line to machine instructions, and run it immediately.

Compilation

Compilation means translating all the code into machine language before running it. Like translating an entire book before publishing it.

Pros: Much faster execution
Cons: Takes time upfront to compile

The Modern Solution: Just-In-Time (JIT) Compilation

Modern engines like V8, SpiderMonkey, and JavaScriptCore use JIT compilation — a hybrid approach that combines the best of both worlds.

The engine starts interpreting your code immediately (fast startup), but while it runs, it watches for "hot" code (functions that run many times). It then compiles those hot sections into optimized machine code for much faster execution on subsequent runs.

It's like a translator who starts translating live, but quickly memorizes frequently-used phrases to say them faster next time.

This is why modern JavaScript is so much faster than it was in the early 2000s — engines got smarter about when and what to compile.

Key Takeaway: Early JavaScript engines interpreted code slowly line-by-line; today's engines use Just-In-Time (JIT) compilation to start fast and optimize as they run, giving you the best of both worlds.