Profile photo for Dan Shappir

As its name implies, JavaScript was originally designed as a scripting language. Scripting languages are programming languages intended for specific run-time environments, that are used to automate various tasks within those environments. A good example of scripting languages are command-line languages for the Unix operating system, such as Bash and Bourne, and PowerShell for Windows. These languages are most often used to encapsulate a sequence of operations that would otherwise need to be executed manually, one operation at a time. Originally JavaScript had a similar purpose, with the run-time environment that it targeted being the browser. (As I described in another answer, it was Java that was originally intended to be the programming language software developers would use to build “real applications” for the Web.)

Despite it's original intended role, Brendan Eich, the creator of JavaScript, designed it as a full-fledged programming language from the get-go. This has enabled JavaScript to evolve from being just a browser-based scripting tool to arguably the most commonly used programming language in the world today. That said, because JavaScript has retained total backward compatibility throughout its evolution, the design decisions that stemmed from being initially intended to be a scripting language continue to influence its behavior today. Some of these decisions have contributed to its great success, and some have caused it to be disliked by many software professionals. Sometimes the same decisions have had both affects.

One such aspect of its design, which is crucial to understanding the operation of JavaScript, it that it does not use Ahead Of Time (AOT) compilation. Most general purpose programming languages require their code to undergo a distinct compilation step before it can be executed. In most cases, this compilation step is performed before the code is distributed to its users. In this compilation step the original source code is transformed into an executable format, either actual machine code, or byte-code to be used by a virtual machine. Because AOT compilation takes place before users even receive the program, it can be a relatively lengthy process that can optimize the entire resulting executable as much as possible. Even more significantly, the compilation step can be used to verify the correctness of the code. For example, many compiled languages are statically typed, which means that variables have a specific type determined for them. If code attempts to assign a value of an incompatible type to a variable, the compiler identifies this, and fails with the appropriate message. The programmer must then fix this error, thus preventing a whole category of bugs from existing in the code.

Like most scripting languages, JavaScript is distributed in its source code form. Avoiding AOT compilation makes JavaScript easier to use, especially by none technical people. They don’t need to install, and learn how to use such tools, and it makes the development cycle much simpler and quicker. But JavaScript code still needs to undergo transformation in order to run, and for that purpose it uses Just In Time (JIT) compilation. The JIT compiler takes the JavaScript source code, as soon as it’s downloaded to the browser, and transforms it into an executable format. Obviously, this step needs to happen as quickly as possible, in order to prevent an unacceptable delay when the Web-page loads. For this reason, while AOT compilers place a premium on the quality and efficiency of the code they generate, JIT compilers place a premium on how quickly they can compile the code.

Also, there is little value to be had from performing code correctness checking in the JIT compiler, as the code has already been delivered to its intended user. Such a user would likely prefer that the code just run, rather than fail because of an error in a code branch that might not even be executed. For this reason, programming languages that use JIT compilation often use dynamic typing, which allows assigning a value of any type to most any variable. This makes such languages even easier to use for novice users, but potentially introduces a whole category of bugs, which might otherwise have been avoided. This is one of the main reasons that some professional developers dislike JavaScript. But this deficiency can be mitigated using best practices such a TDD, and tools / language extensions such as TypeScript and Flow.

A relatively recent innovation in the implementation of JavaScript is the introduction of an optimizing compilation step. After the JIT compiler executes, and while the program is already running, it’s analyzed to identify code that is commonly executed, aka hot code. When such code is identified, it undergoes a more lengthy compilation step, while the program continues to run. This extra compilation emits highly optimized code, and when it’s ready, it is used instead of the unoptimized code generated by the JIT compiler. As a result, in modern environments, the performance of a JavaScript program will improve progressively as it executes, until it approaches the performance of languages that use AOT compilation. You can read more about this mechanism, and other aspects of the inner workings of JavaScript, on the V8 blog (V8 is the JavaScript engine at the heart of the Chrome browser, and also NodeJS).

View 1 other answer to this question
About · Careers · Privacy · Terms · Contact · Languages · Your Ad Choices · Press ·
© Quora, Inc. 2025