Introduction
JavaScript historically used to be an interpreted language, however due to its growing use in web development and the increasing complexity of websites, modern JavaScript uses a mix of interpretation and compilation for faster execution.
Steps in execution of JavaScript code
Here we will be discussing a high overview of execution of JS code.
1) The first step in execution of JavaScript is the parsing of JS code and its conversion into an Abstract Syntax Tree (AST) containing all the information about the code including (but not limited to) :
- type : whether a particular line of code was an if statement, function declaration or a variable declaration.
- location : where that line of code was located in the complete code
-
operators : operators used in the code
All the comments, whitespaces, indentations are gone in this step.
2) In the second step the AST is compiled into unoptimised byte code (note : bytecode != machine code).
3) After that the bytecode is interpreted i.e. the byte code is executed instruction by instruction
4) Now while the bytecode is being executed the JavaScript engiene keeps applying optimisations so that the code can be executed rapidly. This is called Just In Time Compilation (JIT Compilation)
Below is a diagram illustrating the above steps
A side note
What we discussed above was a general flow that JS Engines use while executing JavaScript code, different JS Engines might implement it differently however the overall high level flow mostly remains the same.

Top comments (0)