HN2new | past | comments | ask | show | jobs | submitlogin

In practice, NaN as a literal means that the outcome of a mathematical statement is not expressible. So, the letter 'a' is not equal to NaN (with either two or three = signs). NaN, in other words, has a special meaning.

Dismayingly, JavaScript's isNaN() function diverges from this special meaning, and does something close to what you said -- it tests to see if something is at least almost a number. So isNaN(13/0) and isNaN('foo') both evaluate to 'true', whereas isNaN('1') and isNaN(42) both evaluate to 'false'.



Javascript type coercions might make sense if you realize it was originally designed for a close integration with HTML forms using a simplified proto-DOM ("Level 0").

The idea was more like "isNaN(myForm.myField)"?

For all I know, the above might actually still work. But either way, that explains Javascript type conversion logic.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: