Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Javascript be considered a interpreted language when using Google Chrome (V8)?

I was reading this excellent article on V8, Google's Javascript engine: https://developers.google.com/v8/design#mach_code.

At one point, they say that Javascript is compiled directly into machine language, without any bytecode or an interpreter.

To quote:

V8 compiles JavaScript source code directly into machine code when it is first executed. There are no intermediate byte codes, no interpreter.

So, why is Javascript still listed along with the "scripting" and "interpreted" languages, when it is clearly compiled (in V8, at least)?



Edit: can I somehow create an executable out of Javascript, if it is compiled? That would require somehow linking it to V8?

Considering that question, I found this quote:

V8 can run standalone, or can be embedded into any C++ application.

Here: http://code.google.com/p/v8/.

like image 635
corazza Avatar asked Jul 10 '12 19:07

corazza


People also ask

Is JavaScript considered an interpreted language?

JavaScript (often shortened to JS) is a lightweight, interpreted, object-oriented language with first-class functions, and is best known as the scripting language for Web pages, but it's used in many non-browser environments as well.

Does V8 compile or interpret?

Unlike other languages, The V8 engine uses both a compiler and an interpreter and follows Just in Time(JIT) Compilation for improved performance. Just in Time(JIT) Compilation: The V8 engine initially uses an interpreter, to interpret the code.

Does Chrome compile or interpret JavaScript?

"the machine code that chrome generates is unique to each computer" -- the JavaScript needs to be compiled to machine code that the processor understands, yes. Each JavaScript engine is compiled for a specific architecture.

Does V8 compile JavaScript?

V8 JavaScript engine is an open source JavaScript and WebAssembly engine that compiles JavaScript to optimized machine code before execution.


2 Answers

This is why "interpreted language" and "compiled language" are examples of sloppy terminology. Whether a language is compiled or interpreted is an attribute of an implementation, not of the language itself.

Many people confuse "dynamically typed languages" (like JavaScript) with "interpreted" and "statically typed language" with "compiled", but these are merely correlations rather than absolutes. It is possible to compile a dynamic language (although it's generally trickier than compiling a static one), and it's possible to interpret a static language (eg: Hugs is an interpreter for Haskell).

like image 97
Laurence Gonsalves Avatar answered Sep 30 '22 04:09

Laurence Gonsalves


It is a scripting language because JS code is intended to be supplied and run as source code.

If the coder were to provide a compiled binary for you to execute, then it would not be a script.

Also, no matter what it does on Chrome, the same Javascript source code must also run in other platforms, which may be more or less of a traditional scripting environment. This also doesn't change the nature of the code itself of being a script.

Even if you go to the extreme of compiling it, JS is still a scripting language at heart. There are proper traditional compilers available for virtually every scripting language you can think of (Perl, PHP....); that doesn't stop them from being script languages, nor their source code from being a script.

Likewise, there are interpreters for many languages that are traditionally compiled.

Finally, the issue is further muddied by the concept of "compiling" one language into another. This has been around for a while, but the idea has really taken off with languages like Coffeescript that are intended to compile into Javascript. So what do you call the compiled Coffeescript code?

The terminology isn't really all that helpful, especially now, but the final answer to your question, in the context you're asking it, is that yes, Javascript is still a scripting language.

like image 36
Spudley Avatar answered Sep 30 '22 02:09

Spudley