The original intention of this series of articles is to “let each front-end engineer master the high frequency knowledge, for the work of power”. This is the front end of the eighth cut, I hope friends pay attention to the public number “kite”, armed with knowledge of their minds.

The following uses V8 as an example to illustrate the execution process of JavaScript code, as follows:

The whole process is mainly divided into the following steps:

  1. Lexical analysis, the process of breaking up lines of source code into tokens (tokens are the smallest single character or string that is syntactically impossible to divide);
  2. Syntax analysis, whose function is to convert generated token data into AST according to syntax rules;
  3. With the AST, V8 generates the execution context for that code;
  4. The interpreter generates bytecode (which is code between AST and machine code) from the AST;
  5. The bytecode generation is followed by the execution phase, where the interpreter interprets execution line by line. Byte code in the implementation of the process, if it is found that hot code (such as a piece of code is repeated many times), the background of the compiler will compile this hot bytecode for efficient machine code, and then perform the optimization code again, simply execute the compiled machine code, code execution efficiency.

1. If you think this article is good, share and like it so that more people can see it

2. Pay attention to the public number of kite, and the number of the Lord together to kill the front hundred.