More Fun with JavaScript

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.

written December 23rd, 2010

December 2010

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