Does node.js generate JavaScript compilation?

Node.js uses V8 and compiles JavaScript as an optimization strategy.

So JavaScript running on the server side via node.js / V8 is compiled or interpreted?


source to share

2 answers

The V8 engine compiles javascript into a series of machine code instructions, one function at a time ( usually, the functions won't compile until the first call ).

V8 parses the code and extracts the AST (Abstract Syntax Tree), parses the region to figure out which context the symbol is in, and translates it into machine code instructions.

As you mentioned, V8 is very focused on performance: in addition to the full compiler that compiles every function, V8 consists of an additional compiler that is responsible for optimizing blocks that are identified as frequently used (known as Crankshaft )

No, there is no interpretation of javascript code, but translation and execution of machine code.



Interpreter: A part (core) module of a language runtime / virtual machine that takes specific "actions" against a set of expressions expressed in the language in which the virtual machine is a module.

Compiler: The part (core) of a language runtime module that "converts" a set of expressions expressed in the language whose compiler is the module into a set of instructions native to the architecture in which the expressions are executed.

Standard Node.js is built against V8, which compiles every piece of Javascript code into its own instructions. You can use the -print_code flag on the command line to see which scripts are built and compiled into.

Hope it helps.



All Articles