JavaScript started out as a purely interpreted language, but the distinction has become more blurred over time thanks to performance optimizations like just-in-time (JIT) compilation. This article explains whether JavaScript should be considered a compiled or interpreted language.
Interpreted vs Compiled Languages
An interpreted language like JavaScript is executed line-by-line by an interpreter. This allows for more flexibility since code can be executed as it is written. However, there is a performance cost because the translation to machine code happens dynamically during execution.
On the other hand, a compiled language like C is first compiled statically into fast, optimized machine code before execution. This compiled code runs much faster. But changes require recompiling the whole program.
JavaScript Interpretation
When JavaScript first appeared in web browsers in the 1990s, it was strictly interpreted. The JavaScript engine would translate each line of JavaScript source code into machine instructions which the browser could understand, just-in-time as the script executed. There was no pre-compilation to optimized code like with compiled languages.
Just-In-Time Compilation
Modern JavaScript engines now utilize just-in-time (JIT) compilation to significantly improve JavaScript‘s performance. With JIT compilation, the JavaScript source code is still interpreted but hot code paths that execute frequently will be dynamically compiled to optimized machine code during execution before being executed.
So while the overall execution model is still interpretation, frequently executed functions and loops will benefit from the performance of compilation. In a sense, JavaScript now blends both compiled and interpreted characteristics.
Conclusion
So is JavaScript a compiled language or an interpreted language? The best answer is that it is an interpreted language that leverages compilation. JavaScript source code is interpreted while hot code paths are compiled just-in-time for faster execution.
So while technically JavaScript remains an interpreted language, modern JIT compilation means it benefits from compilation for performance. The lines between strictly interpreted and fully compiled languages have been blurred for JavaScript.


