Skip to content
bebraw edited this page Jan 27, 2013 · 21 revisions

Here's an initial table of contents. I'll convert these into concrete pages as I go on. The Reddit thread contains some of the topics I should go through too so expect updates below.

In the meantime I recommend checking out JavaScript Garden and beginner's resources I've listed over at jswiki, the predecessor of jster.

The book has been aimed for beginners and intermediate level programmers. If you feel that the content could be improved, do submit issues. I'll take those seriously.

JavaScript - a Misunderstood Language?

As you might know the first version of JavaScript was developed in mere two weeks at 1995 by a fellow named Brendan Eich over at Netscape Corporation. Initially the language was known as LiveScript but the marketing men decided JavaScript sounds more believable. After all it was the decade of Java. On retrospect it wasn't a good choice and a lot of confusion has ensued. Java is to JavaScript as ham is to hamster. Keep that in mind!

So how would you characterize JavaScript? Even though it looks a bit like Java or C due to bracing there it is actually an implementation of a couple of powerful languages in disguise. These languages are Scheme, a variant of LISP, and Prototype. From former JavaScript inherited some of its functional programming capabilities whereas latter gave it prototypal inheritance system which in some ways can be considered superior to classical one used by languages such as Java.

Particularly JavaScript's functional capabilities make it in some ways an exceptional language. Prototypal inheritance has caused a lot of confusion but it is possible to get around that. In fact it is possible to implement a classical system using it.

Of course JavaScript comes with the usual imperative programming constructs (for, while, if, etc.) you might expect. There is also some legacy in form of Date and Math modules inherited from Java 1.0. There are some custom features even (with comes to mind) though it is better to avoid some of those.

In fact you can get a lot done by selecting a subset of the language and then using that to its full extent. As JavaScript can feel a bit unwieldy sometimes people have implemented languages that compile to JavaScript. These languages provide some constructs not found in the language and can for instance provide stricter typing.

altJS lists these languages. Have a look at a few of those. Keep in mind, however, that in order to get most out of the languages you are better off learning JavaScript well. It will definitely help when you are trying to decipher the code they generate.

Current State of JavaScript

Particularly in the last few years the usage of JavaScript has grown explosively. Instead of using it to sprinkle some functionality to their sites some people are using it to manage the whole stack from backend to frontend. This has been possible thanks to the increasing popularity of Node.js. A whole ecosystem has grown around it. Particularly NPM has been an important factor in this growth as it has allowed people to share their modules and use ones created by others.

Traditionally this has been a weakness of JavaScript as it does not come with de facto module system. I will get back into this topic later (TODO: link). Let's just say the situation is still a bit messy although it is getting better on the frontend side thanks to solutions such as RequireJS and browserify. The former implements a module definition known as AMD whereas the latter allows to use module semantics familiar from Node on the frontend side.

What makes JavaScript interesting is the fact that it is supported by a wide range of hardware already. Just imagine the mobile devices around that can execute it. And that is not counting all the desktop systems. It is as ubiquitous as a language can get. In some ways it can be considered the assembly language of the web generation. It is that important.

Even though it is widely supported it takes more than just a language to make something useful. That is where browser and server-side APIs come in. Sometimes the APIs aren't particularly easy to use. As the popularity of jQuery shows there is sometimes demand for solutions that make them easier.

During the last few years we've progressed a lot on the browser side. JavaScript engines have become more powerful. This trend was initiated by Google's Chrome and has since led to significant improvements in performance. Standards are supported better. Thanks to Microsoft and its initiatives with Internet Explorer 9 and 10 they've started to catch up with the others and in some ways gone past even. That is a good trend for us web developers as gradually we may start to ditch legacy solutions needed by antiquated browsers such as Internet Explorer 6.

If you have not hopped into the JavaScript train yet, it is a good time to do so now. It's not too late. In fact a lot of development is going on. Newest developments include the introduction of MVC frameworks on the frontend side and reactive programming. Particularly latter seems to be trending currently. There has also been development on the asynchronous side as solutions have been provided that allow us to deal with callbacks in better ways. These include promise and future based solutions. In a way reactive programming yields a solution for this problem too.

The language itself is headed towards a brighter future with ES6. The specification promises to bring forth improvements such as long awaited modules, several language constructs and overall just standard ways of doing things so we can avoid reinventing the wheel ourselves. In fact you can mimic some of the planned features already but obviously it won't look or feel as good. On example of this is generators. I'll discuss this particular case later (TODO: link).

TOC

  • Special Features
    • Hoisting (scope!)
    • Closures (and how to get most out of those)
    • Prototypes (vs. classes as in Java etc.)
    • ???
  • Common Problems
    • var -> highlight globals!
    • function -> define shortcut, use another language? (CS and such)
    • pyramid of doom -> promises, futures, Rx?
    • equality -> it's a mess, use jshint or jslint to remind you
    • hard to find libraries -> use JSter and such
  • Modules
    • AMD
    • CommonJS (Node!)
    • Harmony
    • Transpilers (AMD -> Node, vice versa + Harmony, not 1-1 always)
  • Package Managers
    • Frontend - too many, maybe mention bower (component.json)
    • Backend - Node NPM, use it
  • Build Systems
    • Benefits (minification, improved dev env (LiveReload, precompilers)
    • grunt, jake? others?
  • Boilerplates
    • yeoman
    • ???
  • Full Stack Development