JavaScript

The History of JavaScript

JavaScript is a programming language created by Brendan Eich in September 1995 while working at a company called Netscape. Brendan was given just 10 days to create a working prototype of a language supposed to be the side-kick language for Java that ran in "Netscape Navigator", Netscape’s browser. JavaScript was originally named Mocha, then quickly became known as LiveScript and, was later renamed JavaScript - which will always make beginner developers confuse it with Java.

Brendan had to create a language whose code could be directly written on the 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 are rather interpreted by an engine, and therefore, you can stream bits of source code that the browser can then run.

Why a scripting language?

Netscape wanted to improve the experience and interactivity of webpages. Thinking from first principles, this meant allowing developers to run custom code on their pages. There are two ways to do this: load a previously compiled program that the browser can execute or load the source code itself and run it through an engine.

Loading a previously compiled program would require developing a language, a compiler for Windows, macOS and Linux, and the browser functionality to load and run the compiled program.

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 that look almost the same but they won't be exactly the same.

To fully understand that answer, 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

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's 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 (with the exception of 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 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 standard syntax.