Node.js uses V8 and it compiles the JavaScript as an optimization strategy.
So, the JavaScript running at the server side via node.js / V8 is compiled or interpreted?
-
1V8 has a JIT compiler. See thibaultlaurens.github.io/javascript/2013/04/29/…Dan D.– Dan D.2017年03月29日 20:54:04 +00:00Commented Mar 29, 2017 at 20:54
-
1It seems the answer is in the question... But javascript is a scripting language by nature, and the term compiled is more often used for lower level languages. It's up to the Javascript engine to interprete it at the best. See also: softwareengineering.stackexchange.com/a/138541TGrif– TGrif2017年03月29日 21:40:06 +00:00Commented Mar 29, 2017 at 21:40
-
I'm not sure what you are asking. You've already answered your own question by stating that "it compiles the JavaScript", didn't you?Bergi– Bergi2017年03月29日 23:30:28 +00:00Commented Mar 29, 2017 at 23:30
2 Answers 2
Interpreter: A (core) module part of the language runtime / virtual machine which takes specific 'actions' against a set of expressions expressed in the language whose virtual machine the module is.
Compiler: A (core) module part of the language runtime which 'converts' a set of expressions expressed in the language whose compiler the module is, into a set of instructions native to the architecture where the expressions are run against.
Standard Node.js is built against V8, which compiles every Javascript code snippet into native instructions. You may use --print_code flag in the command line to see which scripts are getting compiled, and compiled into what.
Hope this helps.
2 Comments
V8 engine compiles javascript to a sequence of machine code instructions, one function at a time (usually, functions are not compiled until the first call).
V8 parses the code and extracts an AST (abstract syntax tree), performs scope analysis in order to understand to which context a symbol refers to, and translates it to machine code instructions.
As you mentioned, V8 is highly focused on performance: besides the full compiler that compiles each function, V8 consists of extra compiler which is responsible for optimizing blocks that identified as frequently used (Known as the Crankshaft)
So no, there's no interpretation of javascript code, but translation and execution of a machine code.