JS


JS Foundamentals: Engine Phases


October 3, 2025






Why this topic is important

Understanding the phases of the JavaScript engine is essential to fully grasp how scope works (we talk about it here link) and why certain errors appear at specific times.

The process can be divided into 4 main phases:


four-js-phases



1. Parsing

In this phase, the source code is read by the engine.


If there are syntax errors, they are immediately raised as SyntaxError.


If the parsing succeeds, a tree structure called AST (Abstract Syntax Tree) is generated, which hierarchically represents the code and will be used during execution to establish the order of operations.


When you think of a SyntaxError, think of the Parsing phase




2. Compiling

In this phase:

(we will talk about hoisting and TDZ in the article on Scope here (link))




3. Execution

This is the phase where the JavaScript program is actually executed according to the instructions provided by the AST.


Here runtime errors can occur, such as:



When you think of ReferenceError or TypeError, think of the Execution phase




4. Optimization

In the final phase, the engine tries to run the program as efficiently as possible, optimizing performance based on the resources available on the operating system and hardware. Of course, the topic is more complex than this, and we may cover it in a future article.




When do transpiling and bundling come into play?

In reality, modern development does not stop here. JavaScript applications often go through a series of external tools even before the code reaches the engine:



These tools, as we know, make the code compatible with different environments and browser versions, make writing more productive and maintainable, and produce a final optimized JavaScript ready to be processed by the engine.


Transpiling happens before the engine starts Parsing. It is therefore a blocking process: without it, the engine cannot even begin.




The Correct Order

The correct order for running a JS program is:


Transpiling (external tools) → Parsing → Compiling → Execution → Optimization





full-js-execution-program