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

后端 未结 3 1227
-上瘾入骨i
-上瘾入骨i 2021-01-17 22:18

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

相关标签:
3条回答
  • 2021-01-17 22:54

    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.

    0 讨论(0)
  • 2021-01-17 22:58

    Here, let me demo the code:

      later(); // prove that js is a compiling language
      function later(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 讨论(0)
  • 2021-01-17 23:12

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

    0 讨论(0)
提交回复
热议问题