4

Is JavaScript running on top of web browser?

Like Java running on top of JVM?

Or Does it actually compiled to binary code and run on machine?

0

3 Answers 3

5

V8 (in Google Chrome) contains a JS interpreter and a JIT (Just-in-time) compiler. JS code is converted to V8-specific bytecode. The bytecode is initially interpreted by the interpreter, called "Ignition". When a function becomes "hot" (it is run a lot), the TurboFan JIT compiler produces optimized machine code from the bytecode.

Other modern JS engines use similar strategies. So JS can be interpreted or compiled to machine code (using a JIT compiler), similar to how JVMs work, yes.

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

1 Comment

Can you please mention that how exactly we can compile? how about bytenode package?
1

Javascript isn't truly compiled - it's interpreted on the browser, so yes it effectively "runs on top of the browser" on the client side.

EDIT: I should've started by saying at it's base level. As is mentioned on a comment to this, there are more complex engines now.

1 Comment

JavaScript engines have long moved on from purely interpreting the language - they can quite heavily optimise the code during just-in-time compilation down to native machine code.
0

It has to -- nothing can run on a computer without being the appropriate machine code for the processor.

V8 converts the JavaScript to its own byte code, then is heavily optimized and converted into machine code.

Even the JVM does something similar. The JVM converts the Java byte code into machine code.

3 Comments

JS is an interpreted language. Yes, eventually instructions are sent as some sort of machine code but JS itself doesn't produce that.
@vlaz The specification of it is as an interpreted language - that doesn't mean that the engines have to treat it that way
@vlaz i never said otherwise.

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.