27

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?

3
  • 1
    V8 has a JIT compiler. See thibaultlaurens.github.io/javascript/2013/04/29/… Commented Mar 29, 2017 at 20:54
  • 1
    It 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/138541 Commented 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? Commented Mar 29, 2017 at 23:30

2 Answers 2

23

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.

Sign up to request clarification or add additional context in comments.

1 Comment

those who de-voted this answer, please state why you did so, will you?
15

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.