Blog

5 Ways JavaScript Will Cut You

I recently read JavaScript: The Good Parts by Douglas Crockford. The book attempts to teach JavaScript by extracting its good qualities as a programming language, and by leaving its dirty bits to rot unused on the floor. I, however, found the bad parts much more interesting. Here are six of those curiosities.

Unless functions explicitly return a truthy value, they return undefined. Which is falsey!

Arrays convert all values to strings before sorting.

But you can tell it to sort smartly:

JavaScript has functional scope, not block scope (like C).

JavaScript has a ton of reserved words, and they clash with dot notation.

And those reserved words are:

abstract boolean break byte case catch char class const continue debugger default delete do double else enum export extends false final finally float for function goto hotdog (jk) if implements import in instanceof int interface long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var void volatile while with

parseInt() needs TWO params or it will f&#@ you over.

And that's it! Keep in mind that I am really only mentioning the Bad Parts because they're more likely to cause hard-to-find bugs in your code. The Good Parts are of course worth checking out too.