Javascript - Only Three "Bad" Parts

- - | Comments

I know that Douglas Crockford and many others will disagree with this, but from my point of view, there are only three “bad” parts to javascript.

  1. How does this work?
  2. How does prototypical inheritance work?
  3. Named Function Expression? Function Declaration? Hoisting?

Once a developer understands these three things in Javascript, they’re solidly on their way to rolling their eyes when they’re asked if they are a ninja at cocktail parties. It is these three concepts, in my opinion, that trip up most developers as they start to build applications larger than jQuery spaghetti.

There’s a much longer list in Javascript:The Good Parts and even more in our hearts. But I don’t think that these actually trip us up in daily development. When was the last time that you had a really hard time using the void keyword or were foiled by type coersion? All of these issues, we learn once, and almost immediately understand. Either that, or developers don’t encounter these because the libraries that they use, and learn from, don’t use any (anti-)features either.

Not only are issues like with and eval not often encountered, but also, tools like jshint/lint, remove any accidental uses. Chances are, as long as a developer l/hints their code, they’ll be making a conscious decision to use the potentially dangerous parts of the language. It isn’t so with these three concepts. Without this understanding, it is very difficult to become productive in javascript.

Other than these three concepts, I’d argue that Javascript is no more “bad” than any other mainstream programming language, like PHP or even Java. There are gotchas in every language and at least JS has most of them described very well in The Good Parts and online documentation.

I could give you my own explanations here, but so many others have done a much better job than I could. There are a lot of options. If you still feel confused after reading one, just go on to the next one. If you still feel confused after reading every single one. Find me or someone else in ##javascript on freenode.

How does this work? How does prototypical inheritance work?

The key here is to first learn about prototypical inheritance using Object.create and then come back to trying to understand what the new operator is doing. Most tutorials mess this up, by explaining it the “classical” way first, and subsequently lead to much confusion about following the prototype chain and this and that.

Named Function Expression? Function Declaration? Hosting?

Do you have more examples or blog posts? Let me know on twitter and I’ll add them to this list.

Comments