Skip to content
themooserooster edited this page Nov 25, 2014 · 8 revisions

JavaScript

JavaScript is ubiquitous - it's everywhere! Once known as the language that ran in web browsers, while still true, recent efforts on the part of Google, with their V8 Engine, and the fellows responsible for Node.js, have increased the performance of JavaScript and taken the language out of the browser toward wider application. This means you can write entire apps in JavaScript, from backend to front end, with your whole team speaking the same language!

There's a lot of information on the Internet concerning writing JavaScript apps, here's some execellent resources from from Mozilla, developers of the FireFox web browser:

JavaScript® (often shortened to JS) is a lightweight, interpreted, object-oriented language with first-class functions, most known as the scripting language for Web pages, but used in many non-browser environments as well such as node.js or Apache CouchDB. It is a prototype-based, multi-paradigm scripting language that is dynamic,and supports object-oriented, imperative, and functional programming styles.

In fact, the Mozilla documentation on JavaScript is an excellent source for instruction on learning JavaScript and for quick references to API.

Here's a bit of the history behind JavaScript:

JavaScript is the world's most popular programming language. Why? Because every web browser in the world comes pre-packaged with a JavaScript interpreter.

First thing to know about JavaScript: It has no relation to the Java programming language/plugin/runtime environment. At all. Besides the name. About that...

JavaScript was invented by a really smart guy named Brendan Eich, who was working at Netscape Communications Corporation in 1995. Netscape had basically invented the web-browser 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 the the web was dumber than a box of hammers. 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? Refresh. Updating football scores? Refresh. Seeing if you had any new emails in your inbox? Refresh. And that was slow. And annoying. And meant that you had to stare at a blank, reloading page all the time. On a 56k dial-up modem. If you were lucky.

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 get around the obnoxious page-refresh problem and make 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. It 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. 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.

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. Each operating system would have a different version of the JVM made just for it, 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 Mac and Windows and Linux more or less the same. At the time the idea sounded pretty genius and it made Sun very big 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. Even though it had nothing to do with Java.

So when Netscape Navigator 2.0 was released in early 1996, it shipped with JavaScript and Microsoft was so left in the lurch, that they had to throw in the towel and reverse-engineer JavaScript just so that IE could properly run webpages written for the then-more-popular Navigator.

Here's a few important links within the Mozilla documentation:

© 2014-2015 Operation Spark

Clone this wiki locally