-
Notifications
You must be signed in to change notification settings - Fork 4
JavaScript
##In the Beginning...
JavaScript is the world's most popular programming language. Why? Because today, every web browser in the world comes pre-packaged with a JavaScript interpreter. And because just about every computer (even phones and the ones in car dashboards) comes with a web browser, just about every computer in the world can run JavaScript.
Once dismissed as a super-slow "toy" language that only ran in web browsers, recent R&D efforts at Google, Mozilla, Microsoft, and Apple have made it blazing fast and taken the it out of the browser and into everything from servers to robots.
First thing to know about JavaScript: There is another computer language called Java. JavaScript has no relation to the Java programming language/browser plugin/annoying thing that always needs to update. At all. Besides the name. Which we'll get to...
JavaScript was invented by a really smart guy named Brendan Eich, who was working at a company called Netscape Communications Corporation in 1995. Netscape was started by the guys who basically invented the web-browser as we know it and gotten the jump on Microsoft, who had been too busy taking over the world to notice the whole World Wide Web thing. But they were catching up. Fast.
One thing missing with Netscape's web-browser, Netscape Navigator, was any sort way to program complex behavior on a web page, which meant that your average web page was dumber than a box of hammers. With the exceptions of typing text into tiny boxes, every little thing you did on a page meant the browser had to refresh the entire page to change even the tiniest thing on it. Adding something to your shopping cart on a website? Full page refresh. Updating football scores? Full page refresh. Seeing if you had any new emails in your inbox? Full page refresh. And the poor server who was sending your browser the page had to send you the whole thing all over again, plus that one tiny change you wanted to see. And that was slow. And annoying. And meant that you had to stare at a blank, reloading page all the time. On a horrible thing called a 56k dial-up modem. If you were lucky.
##A Change Is Gonna Come...
The idea that many people were coming to was that if people who made websites had some way of changing the the contents of a webpage after it had already loaded, they could code what they wanted to have happen, and get around the obnoxious page-refresh problem while making some pretty nifty new user interfaces to boot. However, HTML was never meant to be used in any sort of way even close to that. For instance, HTML has no way of making decisions based on changing circumstances. You can't tell a website through HTML "If some condition is true, do this thing I wrote here, if that condition is false, do that thing I wrote over there". HTML simply can't do that because it has no sense of time.
With out time, you cannot have change. How things are is how they are. Even if things did change, without time there was never a period when they weren't this way. For this reason, HTML is what is known as a "declarative" language. It declares how things are in in the present-tense. "This link IS over here. This image IS 500 pixels tall." The thing about the present-tense is, you can't ever change it because there is no future and no past. What was needed in a web browser was an imperative language. An "imperative" is of course a command (it shares the same Latin root word as "emperor"), and in a sense commands are always in the future-tense. This is because they can never have happened yet from the perspective of the one giving the command. When George Washington gave the command to "cross the Delaware", then from General Washington's perspective, frozen in that moment in time on that Christmas Eve, the command is always in the future-tense. Imperative languages describe a detailed set of steps needed to do some task in the future. This allows you to say "When X happens, do Y." The use of "when" is very important. With "when", you can say things like "When the user clicks this button, check to see if there are any new emails and change the page's HTML to show them on the screen." And that's exactly what many smart, highly-paid people at both Netscape and Microsoft figured their web browsers needed.
##Two Browsers Enter...
So the race was on in 1995 to put an imperative programming language in a web browser. Microsoft had been pretty quick to bust out a web browser, calling it Internet Explorer (IE). They had also recently released a pair of programming languages called Visual Basic (VB) and Visual Basic Script (VBScript) for programming Windows applications, and word on the street was that they were planning to build those into IE as well.
In 1994 Sun Microsystems had come up with this programming language called Java, and a program called the Java Virtual Machine. Macintosh (yes, they still said the whole name back then) and Windows would have a different version of the JVM made just for each, but after that, the Java code that you wrote for a program would perform exactly the same across all operating systems. You could write a program once and have it run on any computer, Mac or Windows (Linux had just been invented), more or less the same. At the time the idea sounded pretty genius and it made Sun very big and rich very fast.
So when Netscape felt Microsoft nipping at their heels, the made fast allies with Sun in order to put Java in Netscape Navigator as a sort of pre-emptive answer to Visual Basic. But MS still had VBScript, which was a lighter, easier weekend-warrior kind of programming language. Which brings us back to Brendan Eich.
While the suits upstairs were hashing out the Sun-Netscape alliance, Eich was tasked with coming up with a second, more "light-weight" language that could ship with the upcoming Netscape Navigator 2.0. In 10 coffee-drenched days he took several ideas from some of his favorite (but mostly snubbed languages), mixed them together with a little bit of the ever-popular C language, used NONE of the Java language, and came up with something he called Mocha. But that wasn't confusing enough. So then it was renamed LiveScript. And then the Sun-Netscape deal went through and the suits made him call it JavaScript because Java was supposed to be the "real" language and, per the deal with Sun, they were supposed to tell people JS was just it's kid brother or something. Even though it had nothing to do with Java.
So when Netscape Navigator 2.0 was released in early 1996, it shipped with JavaScript. Microsoft was so left in the lurch by the time the next version of IE came out, that they had to reverse-engineer JavaScript just so that IE could properly run webpages written for the then-more-popular Navigator. They couldn't even call it JavaScript because of trademark issues - they had to call theirs JScript.
Here's a few important links within the Mozilla documentation:
- Another Getting Started JavaScript Tutorial
- A JavaScript Guide
- JavaScript API Documentation
- Glossary of Terms
© 2014-2015 Operation Spark