JavaScript

JavaScript

« Back to Glossary Index

What is JavaScript?

JavaScript, or JS, is a full-featured programming language offering a C-like syntax, first-class functions, prototypal object-orientation, and dynamic typing. It is the language of the web. While there have been attempts to make competitors (e.g., VBScript and early versions of Dart), they haven’t caught on widely, leaving only one generally accepted option for developers if they wish to code business logic and interactiveness into their website.

History

Originally, the first two web browsers, Mosaic and Netscape Navigator, didn’t support any kind of programming. The web was purely text and graphics, essentially only designed for sharing information. In 1995 Netscape decided to add a scripting language called LiveScript to their browser. They had also been in talks with Sun about embedding the Java programming language. But, when that didn’t work out, they may have decided to borrow some of Sun’s stature by renaming LiveScript to JavaScript, forever confusing the public into incorrectly thinking that Java and JavaScript are related in some way.

Microsoft’s first foray into browsers, Internet Explorer 1, was released in early 1995 with no programming language. They quickly reversed engineered JavaScript from Netscape Navigator 2 and released Internet Explorer 2 in November of the same year, which included JScript. These were similar but not quite identical, launching the early days of the web into a system of incongruent support for JavaScript between different browsers and other versions of the same browser.

In 1996 Netscape submitted the JavaScript language to ECMA International in a bid to standardize the language. The first ECMAScript specification was released in 1997. Due to stagnation and lack of cooperation in the industry, however, the viable ECMAScript 5 standard wasn’t released until the end of 2009. Development continued until ECMAScript 6 was released in 2015, which allowed many developers to breathe a sigh of relief – JavaScript had finally reached maturity as a language. Yearly updates are still happening; however, as the language is now considered full-featured, these releases are generally not extensive.

Criticisms

Not everyone is completely enamored with JavaScript. Because the web is full of older scripts that need to run in current browsers, some of the early choices that Netscape made when first creating the language are still with us today and may be impossible to change.

One such concern is that JS is a weakly typed language, which means that you can assign different types of information to the same variable, whereas a strongly typed language would throw an error if this happened. For example, in a strongly typed language, if you declared a variable as an Integer and then tried to assign a String to it, you would get an error. JavaScript, however, doesn’t have any such declaration. You simply create a variable and assign it an Integer, then later assign it a String.

The criticism comes from the fact that if you have an Integer now and then assign a String to the variable later, you probably just made a coding error. But JavaScript is fine with it, and you are none the wiser until it causes an error in production, and your customers start complaining about software bugs.

There are several tools that allow you to add type checking to JavaScript. Some, like Flow and TypeScript, are more of an enhancement to JS, so you don’t have to learn a whole new language. Others, like Dart, are entirely separate languages that compile into JavaScript. Depending on your needs and where you are with a given project, they may offer a helpful path for improving code quality.

Another criticism is that you can’t compile the code. The text the developer writes is the text that ships to the browser for compiling each time the code is run. Yes, you can “minify” the code to convert long variable names into single letters, remove comments and extra spaces, and generally make the file as small as possible to improve download and parsing speed. But it’s still code that needs to be compiled before it can be run, and the web browser does this every time it reloads the script.

Compiled code runs faster, is much harder to read (for humans), and is in a computer-ready state immediately without needing pre-processing. However, Javascript is an interpreted language, not a compiled language, so there is no getting around this limitation.

However, developers love the fact that interpreted languages aid much faster development. Adding the compiling step every time before you can check your code, even if it’s just fixing a typo, can be a significant bottleneck with compiled languages.

Beyond the Browser

When Google released its open-source browser, Chrome, they also released an incredibly fast JavaScript engine called V8. Various projects, including MongoDB and Node.js, have incorporated V8 allowing JavaScript to be used as a scripting language outside of the browser. Many developers are excited about the possibility of using the same scripting language in the browser, server-side, and in the DB rather than the traditional approach of having different languages for each arena. In theory, developers can hone their skills to near perfection and save precious development time by not having to flip between languages throughout the day.

Explore

As JavaScript is the foundational language of the web, there are many, many resources out there. Some are confusing and contradictory, but most are genuinely helpful. Modern sites like Mozilla and ES6 Features are excellent places to start.

« Back to Glossary Index