Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

I am cautious of asking this question because it might appear overly fastidious. I just opened up JavaScript: The Definitive Guide, and it states of the first page of chapter 1

"JavaScript is a high-level, dynamic, untyped interpreted programming language”

So am I to take it that the interpreted part is a requirement in the language specification, or is it misleading to say that the language is an interpreted programming language when respecting the difference between a language and its many implementations?

There are no static compilers for JavaScript apparently - Is there a native machine code compiler for JavaScript? so maybe it's just a reflection of this.

share|improve this question

migrated from Mar 6 '12 at 15:58

This question came from our site for professional and enthusiast programmers.

There was a for a while that was similar to AS3 / the "lost" ES4. It was bytecode-compiled to CIL. –  Hey Mar 6 '12 at 15:53
V8 explicitly claims not to be an interpreter but a compiler. –  pimvdb Mar 6 '12 at 15:56
@GGG JScript.Net is still alive and...sickly. But still alive. –  Jetti Mar 6 '12 at 16:18
FWIW, the "untyped" bit isn't strictly true either –  Rob Agar Mar 6 '12 at 16:54
Firefox had just released the first browser-based JIT compiler the year that question was answered in FF 3.5 so it probably wasn't widely known about at the time. I believe modern JITs actually do a lot of compiling (or at least prep for compile) on the first pass of a JS document to do things like identify and cache methods that are isolated to a given scope. –  Erik Reppen Jun 3 '13 at 18:45

4 Answers 4

up vote 17 down vote accepted

So am I to take it that the interpreted part is a requirement in the language specification, or is it misleading to say that the language is an interpreted programming language when respecting the difference between a language and its many implementations?

EcmaScript language geeks often use the term "ES interpreter" to refer to an implementation of EcmaScript, but the spec does not use that term. The language overview in particular describes the language in interpreter-agnostic terms:

ECMAScript is object-based: basic language and host facilities are provided by objects, and an ECMAScript program is a cluster of communicating objects.

So EcmaScript assumes a "host environment" which is defined as a provider of object definitions including all those that allow I/O or any other links to the outside world, but does not require an interpreter.

The semantics of statements and expressions in the language are defined in terms of completion specification which are trivially implemented in an interpreter, but the specification does not require that.

8.9 The Completion Specification Type

The Completion type is used to explain the behaviour of statements (break, continue, return and throw) that perform nonlocal transfers of control. Values of the Completion type are triples of the form (type, value, target), where type is one of normal, break, continue, return, or throw, value is any ECMAScript language value or empty, and target is any ECMAScript identifier or empty.

The term “abrupt completion” refers to any completion with a type other than normal.

The non-local transfers of control can be converted to arrays of instructions with jumps allowing for native or byte-code compilation.

There are no static compilers for JavaScript apparently

This is not true. The V8 "interpreter" compiles to native code internally, Rhino optionally compiles to Java bytecode internally, and various Mozilla interpreters ({Trace,Spider,Jager}Monkey) use a JIT compiler.


V8 increases performance by compiling JavaScript to native machine code before executing it, versus executing bytecode or interpreting it.


public final void setOptimizationLevel(int optimizationLevel)

Set the current optimization level. The optimization level is expected to be an integer between -1 and 9. Any negative values will be interpreted as -1, and any values greater than 9 will be interpreted as 9. An optimization level of -1 indicates that interpretive mode will always be used. Levels 0 through 9 indicate that class files may be generated. Higher optimization levels trade off compile time performance for runtime performance. The optimizer level can't be set greater than -1 if the optimizer package doesn't exist at run time.


TraceMonkey adds native‐code compilation to Mozilla’s JavaScript® engine (known as “SpiderMonkey”). It is based on a technique developed at UC Irvine called “trace trees”, and building on code and ideas shared with the Tamarin Tracing project. The net result is a massive speed increase both in the browser chrome and Web‐page content.

share|improve this answer
Thanks for this answer, it actually answers the question. I suppose the final comment about no static compilation is what caused the buzz about which implementations actually compile code and which ones do not. All I was interested in was the validity of the statement "JavaScript is an interpreted language" which, given implementation citations and the lack of definition by the spec, appears to be false. Not encouraging for the second paragraph of a "Definitive Guide", but I guess I will stick with it. –  Matt Esch Mar 6 '12 at 18:30
@me232, the statement was substantially true prior to 2008. Rhino pre-dates that but was not a major interpreter and so few would have faulted "the Definitive Guide" at the time for ignoring it. I haven't read the book, so I can't comment on how representative that sentence is of its overall quality. –  Mike Samuel Mar 6 '12 at 20:58

The V8 JavaScript VM used in Chrome doesn't include an interpreter. Instead it consists of two compilers and compiles the code on the fly. One of the compilers runs quickly but generates inefficient code, the other is an optimizing compiler.

I can understand why some people would consider this "cheating", since V8 takes source code as input every time the code runs and the user has to have V8 installed. But consider a compiler which emits an executable which includes a complete interpreter and bytecode. Then you would have a stand-alone program. It just wouldn't be very efficient.

share|improve this answer

The emergence of JIT compilers for script languages has blurred the line between compilation and interpretation to a point where the question doesn't mean all that much. Is it only interpretation when the engine reads a line of code and immediately executes it? (Shell scripts are still typically implemented this way.) Is it interpretation when the engine takes the whole file, immediately compiles it to some byte code, and then interprets the byte code? (The first-stage Mozilla engine works this way, as does CPython.) Is it interpretation when the engine parses a function at a time and JIT-compiles it to native code? What about those engines that compile the entire file to byte code, then JIT one function at a time as needed? (Most script engines these days work this way, and the main Java VM works this way too except that compiling to byte code happens ahead of time.)

There are many shades between compilation and interpretation.

I think the most useful definition for interpretation is "is fed the source code of the program at execution time, without a separate ahead-of-time step". By this definition, all the JavaScript engines are interpreters. But this is certainly not the only possible definition of interpretation.

But is JavaScript designed for interpretation? In a way, yes: it has an eval function as well as the Function constructor that you can give program code as a string which will be executed. The ability to dynamically construct program code at run time requires that the engine is capable of interpreting source code. But this doesn't mean that you can't make everything else ahead-of-time. Even in a compiled language like C++ and C# you can take source code, compile it in memory to new machine code and then execute that. There are even libraries for that: LLVM+Clang in C++ and the Roslyn project in C#.

Also, the delivery mechanism for JavaScript is source code; there is no recognized byte code form of it. C# and Java have their official byte code, and everyone expects C++ to be delivered as machine code. But this is still not an inherent aspect if the language, just a dominant usage scenario. In fact, JavaScript's close relative ActionScript in Flash is in fact delivered as byte code (the Flash compiler precompiles all scripts).

share|improve this answer

There is no totally agreed upon definition of 'interpreted' versus 'compiled'. In the classic distinction, compiled languages produce a stand-alone binary executable, while interpreted languages requires a deployed runtime to execute the code. Virtual machines, bytecode and so on blurs the distinction.

But here is a possibly useful definition: An interpreted language is a language where the standard language runtime is able to take source code text as input and execute it. By that definition Perl, Python, Ruby, JavaScript and shell scripts and the like are interpreted (even if they use intermediate steps like bytecode or even native code). Java, C#, C etc. are not. And JavaScript is by definition interpreted, even if the spec does not use the exact word.

share|improve this answer

protected by gnat May 7 at 13:14

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.