Just-In-Time compilation (JIT)
Computers can only understand Binary code and assembly language which are referred to as low-level languages. In that case, every programming language needs to convert into machine code using an interpreter or a compiler.
In compilation, the entire code converts into machine code at once and write to a binary file (portable file) which can be executed by a computer. In this method, code execution can happen way after the compilation
In the interpretation, the interpreter runs through the source code and executes it line by line. This process read the code and execute it at the same time without generating a portable file
How Just-In-Time Compilation works
If there are no errors in the source code, the parser generates the Abstract Syntax Tree (AST). This is a tree data structure that represents the source code in a tree structure. AST does not contain all the details in the syntax. It represents only content-related information.
Generated AST then convert into machine code and execute right away. However modern JS engines have an optimization method. In this method, the JS engine creates an unoptimized version of the machine code at first and starts to execute it as fast as possible. Meanwhile, the machine code is optimized and recompiled in the already running program execution.
Thank you for reading!