More Fun with JavaScript

December 23, 2010 at 9:42 pm

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.

§

December 2010