Not A Number Is A Number

Javascript Web development May 26th, 2008

Not a numberI recently came across an interesting page called 'Types' in the documentation of my favorite Javascript library, jQuery. It is a brief summary of Javascript language properties, and a very good read that reveals many little known quirks that this untraditional language offers.

One thing in particular caught my attention - the type of the NaN (Not A Number) language value, is surprisingly enough, a number. Try it, write a simple script alerting the typeof of NaN:

var isNumber = NaN;
alert(typeof(isNumber)); // Alerts 'number'

Just another thing to keep you on your toes when working with Javascript ;-)

  • http://orip.org Ori Peleg

    Thanks for the ‘Types’ page link :)

blog comments powered by Disqus