Published in


JS is Compiler or Interpreter Language

It is a very confusing question at which everyone gets stuck!! To find the answer, first, we should know the phases in the JS Engine. That will help us understand whether JS is a Compiler or Interpreter Language.

There are 4 phases in JS Engine — Code Input, Parsing, Compilation and Execution.

JS engine uses Interpreter and Compiler concurrently, so JS is Just in time (JIT) Compilation language and, that’s the reason for this question “Is JS a Compiler or Interpreter Language ?”.

To fully understand how the compiler and interpreter are used simultaneously, we must dive into the compilation phase and execution phase. Those two phases go hand in hand.

The parsing phase provides an Abstract Syntax Tree (AST) as input to the Compilation phase. The compilation phase converts the AST into byte code with help of the Interpreter and sends it to the Execution phase. While the Interpreter goes line by line of code to convert it into byte code at the same time the compiler tries to optimize the byte code as much as it can. In this way, JS use both Compiler and Interpreter. This combination helps to boost its speeds and efficiency. We can say it is hybrid but JS needs JS engine to get the code executed, this is what an Interpreter language requires. And one more thing that should be noted is that JIT is not a full-fledged compiler, it compiles the code before the execution phase.

Firefox and Google introduced JIT for performance and other benefits in browsers. Originally, JS Engine was an Interpreter language, but modern browsers make use of both a Compiler and an Interpreter simultaneously. Accordingly, JS is an Interpreter language.

An AOT compilation is present in some modern JS engines. This means that the Compiler and Interpreter have already perform their work on code and its output will be executed later on.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store