More Fun with JavaScript

Thursday, December 23rd, 2010

I was doing some work with numbers in JavaScript and stumbled upon this most interesting property.

isNaN()
    => true

isNaN(null)
    => false

parseFloat(null)
    => NaN

It would appear that the interpreter can’t make up it’s mind about what null actually is, never mind whether or not it’s a number. Combine this with the [in]famous JavaScript truth table and you have for a very loosely typed language.

§