Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Javascript compile or two-pass interpret?

I'm an admitted novice JavaScript programmer and am attempting to learn more. So I turn to you folks for help, with this easy question :). The O'Reilly book that I'm reading keeps referring to the compile-time of the JavaScript code. My knowledge of functional programming (scheme and the likes) tells me that the JavaScript is actually interpreted by the browser, most likely requiring two passes through the JavaScript.

Am I incorrect in my assessment? Or is the compile-time that the book references actually just the first pass of the interpreter, similar to how Perl or Python would function? Thanks!

like image 712
wfoster Avatar asked Aug 31 '11 02:08

wfoster


People also ask

Is JavaScript interpreted or compiled or both?

JavaScript is an interpreted language, not a compiled language. A program such as C++ or Java needs to be compiled before it is run. The source code is passed through a program called a compiler, which translates it into bytecode that the machine understands and can execute.

What interpreter does JavaScript use?

As we discussed earlier, JavaScript is interpreted by an interpreter named Ignition as well as compiled by a JIT optimizing compiler named TurboFan.

Is node JS interpreted or compiled?

Node. js uses V8 and it compiles the JavaScript as an optimization strategy. So, the JavaScript running at the server side via node.

Is JavaScript interpreted line by line?

JavaScript is actually interpreted line by line.


1 Answers

It is browser-dependent. Look up WebKit's SquirrelFish Extreme and Google V8 to see what's at the fastest end of things, and look at Mozilla's JaegerMonkey for that implementation.

AFIAK V8 and SFX are JITs, so they compile JS code to native. JaegerMonkey and TraceMonkey combine in Firefox to form a system where if code would be faster traced, TraceMonkey executes it, and if code were faster native, JaegerMonkey compiles it, just like SFX.

like image 64
Nathan Moos Avatar answered Sep 29 '22 00:09

Nathan Moos