The History of JavaScript

JavaScript, originally named Mocha, then quickly renamed to LiveScript, and finally JavaScript — new developers may confuse it with Java, but the two are not the same — is a programming language created by Brendan Eich in September 1995, at Netscape, for their "Netscape Navigator" browser. Netscape wanted to improve the user experience and the interactivity of web pages. This meant allowing developers to run custom code on their pages.

Because websites needed to remain independent of the operating systems they ran on, i.e. a website couldn't load a code for Windows, another for Mac OS X (now macOS), and yet another for Linux, but instead load a single code for all of them, that code had to be platform agnostic. Therefore, it falls upon the browser to convert the code it receives into machine code native to the hardware and OS it's running on. The only difference is whether that code is an intermediate code pre-compiled from an existing programming language — much like Java's bytecode or C#'s Common Intermediate Language — or the source code directly.

Because Netscape wanted to offer the best possible developer experience, and fast, Brendan was given just 10 days to create a working prototype of a language designed to be the side-kick language for Java that ran in Netscape Navigator and that could also be directly written in HTML. That meant creating a scripting language.

All scripting languages are programming languages. The theoretical difference between the two is that scripting languages do not require a compilation step (and therefore don't require a compiler) but are rather interpreted by an engine.

So, JavaScript is a scripting language because, even though an intermediate language has huge performance advantages, and could be generated from multiple pre-existing programming languages, it was critical to Netscape's success to allow developers to write source code directly in HTML.

Today we have WebAssembly (abbreviated WASM), a binary instruction format that can be compiled from multiple programming languages, and that has a performance of about 50% slower than native code. For comparison, JavaScript, even with the extremely fast Chrome V8 engine, is around 2000% (or 20x) slower than native code.

JavaScript vs ECMAScript

ECMAScript is the standard specification of JavaScript. Reading the ECMAScript specification, teaches you how to create a scripting language. JavaScript is that specification's implementation. Reading the JavaScript documentation, teaches you how to use a scripting language.

Think of ECMAScript as the blueprint and JavaScript as the house. From the same blueprint, you can make many houses. In the same way, from ECMAScript, we have multiple identical (but not always exactly equal) implementations of it — which we call JavaScript — one for each browser.

To fully appreciate the difference between ECMAScript and JavaScript, let's understand what defines a programming language.

What defines a programming language?

A programming language is defined by its syntax and its APIs.

A programming language's syntax

The syntax is made up of keywords and the way those keywords are structured.

For example, you can write a for loop in JavaScript as:

const array = [1, 2, 3]
for(let i = 0; i < array.length; i++) {
	const element = array[i];
	// Do something with element

While in Python, you'd write:

list = [1, 2, 3]
for i, element in enumerate(list):
	// Do something with element

The keywords are different: there are no const or let keywords in Python.

And the structure is different too: in Python blocks of code are determined by indentation, while in JavaScript they are bound by brackets (except for single-line blocks, where brackets are optional).

When you write code for a compiled language, the available syntax is determined by the compiler. If the compiler understands your keywords and how they're structured, then it can compile your code and you can run it. If it doesn't understand them, then it cannot compile your code and you cannot run it.

So, in practice, the compiler defines the language's syntax.

The need for standard syntax

But there's usually a need for multiple compiler implementations that focus on different aspects: target operating system, compilation speed, code optimization, debugability, analysis, integration with IDEs, and licenses — to name a few. So generally a programming language has multiple compilers to choose from.

And herein lies the need for standards.

If you only had one compiler, you could document whatever syntax that compiler supports as the official syntax for the language. But when you have multiple compilers and differences between them, the need for standards becomes obvious. This standard specification contains the syntactic rules that all compilers must comply with.

So, in theory, a standard specification defines the language's syntax.

Theory vs Practice

I make the distinction between theory and practice evident because in the case of JavaScript's syntax, there is a gap between the theoretical language's syntax (i.e. ECMAScript) and what you can use in practice (i.e. the JavaScript browser engines understand).

When a new standard comes out, not all browsers implement all those features all at once. That's why we need something like Babel (that used to be called 6to5) to translate code written in modern ES6 to ES5, the previous specification of the ECMAScript, to give developers the ability to use modern JavaScript while giving browsers time to catch up to the updated specification.


Want these posts on your email?