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.

console.log(isNaN());
// => true
console.log(isNaN(null));
// => false
console.log(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

Can’t find what you’re looking for? Try hitting the home page or viewing all archives.