Check out a free preview of the full JavaScript the Good Parts course:
The "The History of JavaScript" Lesson is part of the full, JavaScript the Good Parts course featured in this preview video. Here's what you'd learn in this lesson:

JavaScript started with HyperCard. The developers of the first web browsers like Mosaic and Netscape wanted a way for people to make web pages interactive much the same way HyperCard made the Macintosh operating system interactive. First came LiveScript then came JavaScript. ECMAScript evolved to its third edition in 1999. The fourth edition was abandoned. The fifth edition was released in 2009. It turns out ten years between editions ended up being a good thing for JavaScript. The bad parts of JavaScript stem from Legacy, Good Intentions, and Haste. For the most part, these can be avoided.

Get Unlimited Access Now

Transcript from the "The History of JavaScript" Lesson

[00:00:00]
>> [MUSIC]

[00:00:03]
>> Douglas Crockford: Okay, so before we get into chapter two, were there any questions leftover? No, really? All right, so let's recap. First, there was the Big Bang, then the Dawn of Man and then JavaScript. So I discovered that JavaScript has good parts and this was the first important discovery of the 21st century.

[00:00:31] Thank you and it was a surprising discovery when I first published my results. There was enormous skepticism that no way can't be any possibility that JavaScript actually has any good parts in it that can't be true, but it is born out. It is in fact, true. JavaScript has some of the best parts ever put into a programming language.

[00:00:52] So the old timers might remember Mosaic. It as the first popular web browser developed at the University of Illinois by a bunch of kids there and many of who are now extremely wealthy. They went off and some of them started a company called Netscape, which made the first mass market browser.

[00:01:14] Their plan was to produce a browser, get everybody to use it and then start charging $30 a year use it. Their ultimate plan was that everybody in the world would give them $30 a year and that probably be okay.
>> [LAUGH]
>> Douglas Crockford: But it didn't work out that way.

[00:01:34] So before then, Bill Atkinson at Apple developed something called HyperCard. At that time, Apple was struggling with the macintosh platform. They were having a difficult time convincing developers to write for it. The difficulty was that macintosh required an event driven programming model, which was the opposite of what programmers were used at that time which was a conventional blocking on read architecture.

[00:02:07] And they look at the mackintosh and said, we can't write for that, it's all inside out. It's too hard. Wow, we can't do that. Atkinson designed this whole thing called HyperCard. Took MacPaint and allowed you to paint on several layers, and just lay any layer at one time.

[00:02:23] We called that a card and you could attach to those cards buttons, and fields, and attached to those event handlers which could read things like on-click and on-mouse up and things like that. And added a friendly little scripting language to make that easy to do and beginners loved it.

[00:02:46] They had no idea that this style of programming was hard, nobody told them. So they wrote amazingly sophisticated applications in HyperCard. And eventually the professional developers say, well, if they can do it, I guess we can do it. And eventually took off in Macintosh in the Windows and everything after that, but it sort of started here.

[00:03:07] And so the guys at Netscape thought, they wanted a similar kind of capability in the Netscape browser should be called Navigator. That beginners could very easily take a web page, put some buttons and fields on it and make it interactive and they got this guy to do it.

[00:03:29] This is Brendan Eich, the creator of JavaScript. He was given about ten days to design and implement a language that would do this which is an insanely short amount of time to design, and implement a programming language, and the DOM, and all the other crap that went with it.

[00:03:50] An amazing achievement, but Netscape was a horrendously mismanage the company that go to market with such an idea. So Brendan took from Java its syntax and if most of the bad parts of JavaScript came from that lineage. He took scheme is a language that was develop at MIT, which began as an experiment to try to understand Carl Hewitt's actor model.

[00:04:22] Carl Hewitt is this amazingly smart guy who got all excited about actors as a new paradigm for how programming should be done. I think Carl was right, but there are other guys at MIT who just couldn't understand what Carl was talking about. And so they decided to write a Lisp dialect that would demonstrate some of good things Carl is talking about.

[00:04:43] And in the process, they accidentally invented Scheme. The best part of Scheme was functions has first class objects with flexible scoping which hadn't been done before and was brilliant, but the mainstream never bought into it, because Lisp always had all those parenthesis. And at least when you're beginning, you have to count them all and mainstream developers just had no tolerance for that so it went nowhere.

[00:05:12] The first language to take that idea to the mainstream and be successful with it was JavaScript. So in doing that and one of the audacious thing to do that Brendan is designing a language for beginners to do simple scripting and he takes one of the most powerful features from experimental language, and sticks it in there, and doesn't tell anybody.

[00:05:34] He didn't tell anybody that he had done that amazing, then Self was another research language being developed at Xerox PARC. Self was a dialect of Smalltalk and they wanted to make Smalltalk more expressive, easier to program, more dynamic and faster to implement and they did that by removing classes from Smalltalk.

[00:06:03] Smalltalk was the first main stream object computer programming. They took the classes out instead had objects inherit directly from other objects. Removed a big level of interaction in the process, came up with a language which could be much faster. And more importantly, much more expressive. So it became much easier to write highly dynamic programs in this language.

[00:06:25] Brendan took that another feature from an ignored research language and stuffed it into a language for beginners. Amazing and it turns out the interaction of those two features, having dynamic prototypal objects with functions as first class objects. Putting those together was astonishingly smart. And so we ended up with something that at the time we called LiveScript.

[00:06:53] Now at that same time in history, Java was taking off. In 1995, Java was the biggest thing ever to happen in the industry of software. Java applets were going to rule the world. Some promised that Java applets would liberate us from Microsoft, because we would write to the virtual machine not to the operating system.

[00:07:16] And therefore, we could get off of Windows and be free and there's a lot of interest in that. At the same time, Netscape was making a similar promise that we'll target all applications to the browser. The browser is OS independent. We'll be liberated from Microsoft. Together, we will destroy Microsoft and Netscape realized that they needed to form an alliance.

[00:07:42] Because if they both win against Microsoft on their own, Microsoft could play them off against each other and they're both lose. So step one of their alliance, add Java to the Netscape browser. Okay, Netscape agreed to do that. Step two, Son required. You kill LiveScript, because we've told the world that JavaScript is the last language anyone's ever going to need.

[00:08:05] So it's really embarrassing to have this other language in there, which isn't Java. We can't explain that, that doesn't make sense of get rid of it. Netscape couldn't do that. Because for a couple of reasons, one was a technical reason. And so they had this crappy DOM in there.

[00:08:23] It was called DOM zero or later became called zero and LiveScript was able to talk to it and do stuff to it. Java couldn't. So the way Netscape figure out to get Java in there fast was to create a bridge LiveScript and Java called LiveConnect. And that was a little API that allow the script language to see Java objects, so they can kind of push the stuff back and fort, that was the only mechanism by which Java could communicate with the browser.

[00:08:55] And they didn't have time to rearchitect that and take it out and create a new DOM, specifically for Java. The other reason was they wanted a language that beginners could use and Java is not that language. You have to have a lot of knowledge about Java in order to write hello world.

[00:09:14] So the barrier to entry is really high. Beginners can't do it. So they thought there was still a mission for this language. So they refused to take it out. So they bickered about that and they were at an impasse and their alliance was about to breakup. When Marc Andreessen, one of the founders of Netscape, maybe as a joke suggested that they change the name to JavaScript.

[00:09:36] And that the position it as a subset of Java, a scriptable Java. Java's stupid little brother interpreted Java which is crazy, because Java once interpreted Java. So they went out in public and they lied. They lied about what this programming language was and what it's relationship to the world was gonna be.

[00:09:58] Now through all of this, Microsoft started to notice there are these two companies in California that are about to destroy Microsoft. So we need to look into this. At that point in time, Microsoft's opinion of the future telecommunications was fax. So they completely missed the web. And so when they saw Netscape's during the heat up, they decided, okay, we need to get into the we business.

[00:10:21] So they bought a company called SpyGlass that was another spin off from University of Illinois, relabeled it as Internet Explorer 1 and got into the race. They also wanted to knock off JavaScript, so they created their own language called VBScript which they hope would eventually win. But to hedge their bets, they also reverse engineered JavaScript and they did the best job of reverse engineering in the history of Microsoft.

[00:10:53] They looked very carefully at what had done and found every error, every design defect, every mistake, carefully cataloged them and replicated them. Usually Microsoft can't resist doing things the Microsoft way. But in this case, they went the high fidelity way which is why we're here. Cuz if they had done what they usually do, there would have been no compatibility between the two and the language would have died, but they didn't.

[00:11:25] And because of that high protection, it still survives. Now they didn't want to call it JavaScript, because Son took on a ship of the JavaScript trademark even though they had nothing to do with the design of the language. At that time, Son was shaking down coffee companies. Because they were using the word Java, this was true.

[00:11:44] So Microsoft decided to call it JScript. So then it got taken to Netscape. I don't know we're gonna get embraced and extended, so need to get a standard to keep Microsoft in check. So they went to W3C. So W3C, we developed this language for the web. We'd like you to standardize it and it turned out W3C had been waiting for a chance to tell Netscape to go to hell.

[00:12:08]
>> [LAUGH]
>> Douglas Crockford: So they told Netscape to go to hell. So Netscape shopped around looking for another standards body they tried ISO. Eventually they ended up at the European Ccomputer Manufacturers Association and which has a long way to go for a California software company, and ECMA agreed to to create a standard.

[00:12:30] So they convened a committee and Microsoft join the committee, and Microsoft dominated the committee. So when questions came up like Brendan wanted to fix the double equal operator, he thought as long as we're standardizing, now is the time to fix it. Microsoft said, no. All of those defects have been so carefully cataloged and identified, and replicated are now locked into the standard.

[00:12:55] The last bit of business they had was what do we call it, cuz Netscape said, you can't call it JavaScript. Because that's a Son's trademark and we have an exclusive license to use it, so you have to call it something else. At that point, ECMA should have told them to go to hell, but they didn't.

[00:13:11] And they kicked around different titles like Netscript, Webscript. It couldn't agree on anything, so they published it with the working title was ECMAScript which is maybe the stupidest name ever put on a programming language, but that's what it is. And the people who are still confused about who think that JavaScript, JScript and ECMAScript are different languages and they're not they are synonyms for the same silly language.

[00:13:38]
>> Douglas Crockford: So the language that is an IE6 was the third edition, which was published in 1999. The fifth edition didn't come out til ten years later, the fourth edition was abandoned and it was never approved. That's a long time between editions, but it turned out that was really good.

[00:14:00] Because joining the browser wars, the web as a platform was a extremely unstable. Netscape and Microsoft were pumping bugs into the web at a furious rate, and it was really hard for developers to keep up with that. Also bugs tended not to disappear, they would just get added on to.

[00:14:20] And so it really wasn't feasible to write JavaScript programs at that time, but having ten years in which nothing happened. Our allowed for the language becomes stable and often with stability is much more important than anything else, because you know where the errors are and you are not gonna get tricked or trapped to confused.

[00:14:44] And so in 2005, it was possible for AJAX to take off, because the language had sat around for so long. So the new language defines actually two languages. There's a default language and a strict mode. And I recommend that in the short-term, if you have to run an IE6 or anything before IE10.

[00:15:09] They will be working in the intersection of ES5 and Strict. That turns out that's multiple language. So that's a pretty easy place to live. In the long-term, you wanna be working in ES5/Strict, because that's gonna be the future of the language. The next edition will be built on top of that.

[00:15:26] Avoid the default language, because that's going to be a default language. Why does JavaScript have so many bad parts? A lot of it is due to legacy that it borrows a lot from C and Java, and those languages got a lot wrong. And somehow we're more forgiving of it in those languages.

[00:15:48] When we see those mistakes in Java for some reason, they just seem nastier. Also there are a lot of good intentions that Brendan put in very quickly like semicolon insertion and the width statement which turned out not to be good, and there's a lot of that in the language.

[00:16:06] We'll be talking a lot about that. But mostly, it was haste. I mean, he had ten days to figure this stuff out. In contrast, Smalltalk which was developed at Xerox Parc, they spent almost as many years as Brendan spent days in this design and perfecting of that language.

[00:16:27] Smalltalk is a brilliant design. There is brilliance in JavaScript, but there is a lot more that is not. The good news is for the most part, the bad parts can be avoided and the problem with the bad parts isn't that they're useless,. It's that they're dangerous. And so it requires discipline to avoid their use.