What is JavaScript?
Who JavaScript was built for and why it was written in ten days, why it lets so many mistakes through, why it can't take back its old decisions, and how it reached far beyond the browser.
Play video: What is JavaScript? Explained in 8 minutes
Next lessonJavaScript data types and operatorsIn this lesson
Transcript
Intro
Almost every website you've ever opened runs on JavaScript: 98.9 percent of them, by one count. Its first version was written in ten days. How does a ten-day prototype end up running the web? Today, we find out.
This is the first episode of a new series on JavaScript. Over the next few videos we'll go from the smallest pieces of the language to how they fit together into working programs. We'll cover what those pieces are, how to organize them, and the ideas that decide how they behave. And we won't stop at the basics: later episodes dig into the parts of the language that trip most people up, and why they work that way. Each episode stands on its own, but they're built to be watched in order.
By the end of this video, you'll understand three things. One: who JavaScript was built for, and why it was built in such a rush. Two: why it lets so many mistakes through. Three: why it can't take back its old decisions, and how it reached far beyond the browser anyway.
Ten days
In 1995, the web was mostly documents. A page could show you text and pictures, and not much else. Netscape made the browser that was taking over, and it wanted pages that could do more. That April it hired a programmer named Brendan Eich. Netscape was already striking a deal to put Sun's Java in its browser, and it wanted a simpler scripting language to go with it. Eich had to prove the company could build one in time. In May, he wrote a working prototype in ten straight days. Its code name was Mocha.
The plan split the work in two. Java was for professional programmers. The new language was for the people writing web pages. Netscape's co-founder, Marc Andreessen, wanted it so easy that anyone could type a few lines straight into a page.
One of its common early jobs was checking forms. Without it, you'd fill in a form, send it to the server, wait for a new page, and only then find out you'd mistyped something. With it, the page could catch the mistake right there.
Why it forgives
That audience shaped how the language behaves. To make it easier to pick up, JavaScript converts values automatically when an operator gets a type it didn't expect, instead of stopping. Some of those rules came straight from its first users. Netscape's own staff asked for the text four-oh-four to match the number four-oh-four, because that's how web status codes reached their code.
Start with that text, four-oh-four. Add 1, and you get four-oh-four-one, because the plus sign turned your 1 into text and stuck the two together. Subtract 1, and you get four-oh-three, because minus only works on numbers, so the four-oh-four became one. Neither line gives you an error. If you meant something else, nothing tells you.
Automatic conversion is only one of three features behind this. The first is dynamic typing: values have types, but a variable isn't tied to any of them, so it can hold a number now and text later. The second is implicit conversion, and its rules can surprise you: 1 equals the text 1, and 1 equals the text 1.0, but those two pieces of text don't equal each other. The third is flexible objects and functions: an object can gain new properties while the program runs, and a function can be called with more or fewer arguments than it declares.
You get a language that's quick to start with, and you pay for it later. A stray piece of text can slip through, and the program carries on with the wrong number. Eich himself co-wrote that these conversions became "a significant source of confusion and coding bugs" as the language grew. JavaScript still throws errors in plenty of situations. It just lets more through than stricter languages like Python or Rust.
The name
Mocha didn't keep its name. When it first reached the public that September, in a test version of Netscape 2, it was called LiveScript. By December it had become JavaScript, announced by Netscape and Sun together, with a press release calling it a complement to Java. Managers at both companies had also insisted it should look like Java. That's as far as the link goes: they're separate languages, and you can't swap one for the other. Sun trademarked the name, and Oracle owns it today.
The rulebook
Microsoft saw those test versions too. It worked out how Netscape's language behaved and built its own, called JScript, for Internet Explorer. The two didn't match, so a page could work in one browser and fail in the other. In November 1996, a committee met under a standards body called Ecma to write one shared rulebook. It needed a name for the language, and Sun wouldn't license JavaScript. So the committee kept using a placeholder, ECMAScript, and the placeholder stuck. The first edition came out in 1997. Chrome, Firefox, Safari and Edge all follow that standard today, and most people still just say JavaScript.
No take-backs
Those early decisions are still with us, because of how the web works. A browser reads a page's code fresh every time someone opens it, and plenty of old pages have nobody looking after them any more. Change how the language behaves, and those pages break. So the people who run JavaScript work by a slogan: don't break the web. Once something ships, it almost never leaves.
Even Eich lost that argument. In 1997, he tried to take the conversions out of the double-equals operator, and was told too many pages already depended on them. A slip in the first version means type of null still answers object, and changing it now would change what existing code does. And in 2018, a new feature called flatten had to be renamed flat, because testing it broke a popular site built on an old library called MooTools.
Editions
Every edition since has had to work around that rule. The third arrived at the end of 1999 and stayed current for ten years. A much bigger fourth edition was worked on for years, the committee couldn't agree on it, and in 2008 they gave up. A smaller fifth followed in 2009. The sixth, in 2015, was the largest yet, and it picked up ideas left over from the fourth. Since then there's been a new edition every year, each one building on the last.
New features still have to reach each browser, and they don't all arrive at once. So before relying on something new, developers check which browsers support it, usually on a site called Can I use.
Beyond the browser
Browser makers couldn't really compete on language features, so they competed on speed. In 2008, Google's Chrome launched with a new engine called V8, and it set a new bar for how fast JavaScript could run. The next year, Ryan Dahl began building Node.js on top of V8, which let JavaScript run on servers, and newer runtimes like Deno and Bun do the same. Electron goes further: it packs Chromium and Node into desktop apps, including VS Code and Slack. We'll give Node a whole episode later in this series.
Next time
That's JavaScript in one line: written in ten days for people writing web pages, stuck with its early decisions because the web depends on them, and now running far beyond the browser. Next time, we start with values, types and operators, the pieces every program is built from.