NaN, what are you?

I’ve been using Javascript lately and it has actually been quite a pleasure to use. I never thought I would say that.

I think my original discomfort with Javascript is a natural one. To me, things were too inconsistent and so I was never confident that what I was writing would translate properly. Java programmers often feel the same way when moving to C/C++.

Ultimately, it comes down to understanding the language’s design goals. Javascript’s goals are a bit strange and at times ugly; however, you don’t mind it once you’ve learned to ignore those bad parts. You learn to have discipline rather than trust Javascript’s forgiving nature (which is often the cause of confusion). The rest is extremely flexible, convenient and powerful.

One bit I find amusing with Javascript is NaN. Arguably, NaN is a bit quirky in most languages, but I never realized how much so until Javascript. (For those of you that don’t know, NaN stands for “not a number”). Consider:

typeof NaN === 'number'; // true
NaN === NaN; // false
NaN !== NaN; // true

On another note, I was thinking on the train ride to work about what the worse possible interview questions would be. For some reason, I can see myself interviewing some poor college kid in the future and being extremely evil, possibly as a joke. I can imagine some triviality like this one making that list. For example, the question would be: Fill in the blank:

___ === ___; // false
___ !== ___; // true

And the hint would be:

typeof ___ === 'number'; // true

Another terrible question was: “Find x strings that match the regular expression y”. I wonder if asking them to build a simple regular expressions matcher is reasonable though.

Leave a comment

Recent Entries

  • New York City

    I spent last weekend in New York City. It was my second time in New York but the first time I really got to see...

  • Ctrl, Alt, Delete

    My life has been crazy and it looks like the weeks will only get even more hectic. I always measure how busy I should be...

  • Perspective

    Despite the lack of activity on this blog for so long, I was surprised to learn that I still am getting more traffic than before....

  • Back!

    Sorry. I was gone for a long time. Blogging is a paradox. You can never be doing interesting things and blogging at the same time....

  • Good Service

    It was my girlfriend's birthday today and to celebrate, we went out to eat at a nice restaurant in Sacramento. Sacramento had a wine-and-dine week...

Close