最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

I was reading this excellent article on V8, Google's Javascript engine: .

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: /.

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/.

Share Improve this question asked Jul 10, 2012 at 19:58 corazzacorazza 32.4k39 gold badges120 silver badges191 bronze badges 8
  • 2 If that is the case, then it isn't really a [java]"script" anymore. Could just as well call it "JavaCompiled" instead :) – Quintium Commented Jul 10, 2012 at 20:01
  • Damn, but JavaScript sounds so... Juicy. – corazza Commented Jul 10, 2012 at 20:02
  • 2 I don't think that he implied that, @GabyakaG.Petrioli, he simply separated the words... – corazza Commented Jul 10, 2012 at 20:18
  • 1 yes.. but by separating the words he implies that the java part has significance on its own ... (anyway ... i am just stating this for the casual reader..) – Gabriele Petrioli Commented Jul 10, 2012 at 20:19
  • 1 @GabyakaG.Petrioli - I know it isn't Java. It was a joke on words. Calling something with "script" but compile it instead just changes things. Sorry for confusing you. – Quintium Commented Jul 10, 2012 at 21:27
 |  Show 3 more comments

3 Answers 3

Reset to default 19

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).

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.

Here, let me demo the code:

exeFuncDefinedLater(100); // prove that js is a compiling language
  
function exeFuncDefinedLater(num) {
  console.log("Your number is: " + num);
}

This piece of code could run both on Chrome Browser and Node js.

If anyone says that js is an interpreted language, then this piece of code would crash, as when u run later(), it should not know the later function body.

This could prove that js is a compiled language, as it compile later function (so machine could know it), then execute it.

发布评论

评论列表(0)

  1. 暂无评论