/    /  Javascript-Engine

Javascript-Engine

 

JavaScript is a multi-paradigm prototype-based language. Which uses JavaScript Engines such as Chrome’s V8 engine Firefox SpiderMonkey engine and etc. They convert the high-level code into machine-readable code which lets the computer to perform some specific tasks. We will understand this using an image.

 

Javascript-Engine

 

Google chrome’s JavaScript V8 engine:

 

Firstly, the raw JavaScript file goes into the Parser.

 

Parser: It checks for syntax and semantics. The parser is nothing but a lexical analysis that results in the breaking of code into tokens in order to understand their meanings and these tokens get converted into Abstract Syntax Tree(AST).

 

Abstract Syntax tree: It is a hierarchical tree-like structure of program representation that allows the interpreter to understand the program. This AST is initially going to the Interpreter.

 

Interpreter: It lets the AST to get converted into Byte code. In the V8 engine, this process is known as Ignition but when some code gets repeated again and again.

 

Profiler: It will check for the repeating code that can be optimized. As soon as, it gets the repeating code, it basically moves the code into the compiler.

 

Conformance test:

 

Chrome’s V8 Engine -> 98%

Mozilla’s SpiderMonkey -> 87%

 

For example:

 

// Arrow function
const multiply = (a, b)=> a*b;

for(let i=0;i<1000;i++){
  console.log(multiply(4, 3));
}

 

We are calling the multiply() function 1000 times. When this code goes into the interpreter, the interpreter performance got decreased, since, Interpreter had to repeat this code again and again and then the profiler will mark this code as warm and comes into action.