This is nonsense. Most modern languages compile, even so-called interpreted languages like Python and Ruby. (they compile bytecode for their own stack-based VMs, but they compile nonetheless.) JavaScript compiles on most execution platforms. It has a JIT COMPILER, which is like any other binary compiler except that it works at runtime rather than beforehand.
In fact, JavaScript is faster than most interpreted languages because the JITs for it are quite good. Lua is often faster, however. Julia (a fairly new interpreted language) is basically always faster.
Java compiles to JVM bytecode at compile-time, but, like JavaScript, it is JIT compiled at runtime, but it is nonetheless generally faster. Go and Haskell are statically compiled to binary, but they are still sometimes slower than Java. Common Lisp is also compiled but rather slow.
Compiling to binary at runtime is not a make-or-break difference. Julia is faster than most statically compiled languages (Not C/C++ or Fortran, but most of the others, including Go and Java), but it compiles at runtime.
The reason C++ is faster is that it’s very natural to allocate memory for your data structures in advance, and C++ data structures can often be packed much more efficiently into contiguous blocks of data, which make it much easier for the processor to optimize for the cache. In JavaScript, because of the dynamic nature of the language, any variable name could point to any data type. This makes it much more difficult to allocate in advance, and much more difficult to pack data in arrays (it’s just a bunch of pointers to objects on the heap). Even when the JIT figures out how to optimize something, it needs a bunch of runtime type assertions to make sure it did the right thing, and it can fallback to slower code if it was wrong.
In short, C++ tries to force the programmer to organize data in a way that is efficient for the machine. JavaScript is focused on making data organization easy for the programmer and can’t give the machine any guarantees about what it will need before the code runs. (The reason Julia is so fast, even though it’s interpreted is that it can give the machine more guarantees about memory allocation. This is also true of Java, which is JIT compiled at runtime.)
In fact, JavaScript is faster than most interpreted languages because the JITs for it are quite good. Lua is often faster, however. Julia (a fairly new interpreted language) is basically always faster.
Java compiles to JVM bytecode at compile-time, but, like JavaScript, it is JIT compiled at runtime, but it is nonetheless generally faster. Go and Haskell are statically compiled to binary, but they are still sometimes slower than Java. Common Lisp is also compiled but rather slow.
Compiling to binary at runtime is not a make-or-break difference. Julia is faster than most statically compiled languages (Not C/C++ or Fortran, but most of the others, including Go and Java), but it compiles at runtime.
The reason C++ is faster is that it’s very natural to allocate memory for your data structures in advance, and C++ data structures can often be packed much more efficiently into contiguous blocks of data, which make it much easier for the processor to optimize for the cache. In JavaScript, because of the dynamic nature of the language, any variable name could point to any data type. This makes it much more difficult to allocate in advance, and much more difficult to pack data in arrays (it’s just a bunch of pointers to objects on the heap). Even when the JIT figures out how to optimize something, it needs a bunch of runtime type assertions to make sure it did the right thing, and it can fallback to slower code if it was wrong.
In short, C++ tries to force the programmer to organize data in a way that is efficient for the machine. JavaScript is focused on making data organization easy for the programmer and can’t give the machine any guarantees about what it will need before the code runs. (The reason Julia is so fast, even though it’s interpreted is that it can give the machine more guarantees about memory allocation. This is also true of Java, which is JIT compiled at runtime.)
COMMENTS