s JavaScript Interpreted or Compiled? Let's Find Out


If you're new to JavaScript or coming from a compiled language like Java or C++, you've probably wondered: is JavaScript interpreted or compiled?
You may have even heard both. "JavaScript is an interpreted language." Or, "Modern JavaScript is compiled by the engine." So... which is it?
Let’s investigate this like a puzzle — and come to a conclusion together.
Traditional Definitions of Compiled vs Interpreted Languages
Traditionally:
Compiled languages are translated entirely into machine code ahead of time (AOT), like C or Rust or compiled into bytecode before execution like Java. Once compiled, the program runs directly on the hardware.
Interpreted languages execute code line-by-line at runtime without a separate compilation step, like early Python or shell scripts.
JavaScript started as an interpreted language — engines read and executed code directly. But the story has changed.
What Happens When You Run JavaScript?
Let’s imagine you run a JavaScript file. What does the JavaScript engine (like V8 in Chrome or Node.js) do?
Parsing: The engine first parses the code — it reads the text and turns it into an Abstract Syntax Tree (AST). This process checks for syntax errors and organizes the code structurally.
Compilation: Wait — did we just say compilation? Yes! Modern JavaScript engines like V8 compile the code into machine code using Just-In-Time (JIT) compilation.
Execution: Once compiled, the code is executed. The engine may recompile optimized versions based on how the code behaves at runtime.
This sounds... pretty close to a compiled language. So is JavaScript compiled?
Just-In-Time (JIT) Compilation Explained
JIT compilation is a hybrid approach:
JavaScript code is initially parsed and converted to bytecode or machine code just before execution.
The engine monitors code behavior to optimize “hot” (frequently executed) functions by recompiling them with performance improvements.
If the assumptions made during optimization become invalid, the engine can deoptimize and recompile again.
So What’s the Answer?
JavaScript today is both interpreted and compiled. More precisely, it's dynamically compiled at runtime — thanks to JIT compilers like V8.
It is not ahead-of-time compiled like C or Rust.
It is not purely interpreted like early scripting engines.
It is parsed and compiled just-in-time into optimized machine code.
Conclusion: JavaScript Is More Compiled Than Interpreted Today
While JavaScript still parses and executes dynamically, the dominant work happens in compilation to machine code at runtime.
This means:
Your code is not executed line-by-line purely in textual form.
Most engines run compiled, optimized machine code during execution.
The compilation step is automatic and invisible but essential for speed.
Thus, JavaScript is closer to a compiled language, albeit with unique runtime dynamics.
Subscribe to my newsletter
Read articles from Saeid Keyvanfar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
