java wrote:
There is an introductory diagram for those confused by
javascript type wrangling (i.e., runtime type conversion
by the javascript interpreter).
http://mollypages.org/misc/jstypes.mp
It's not comprehensive but covers most common scenarios.
On that diagram the statement "null and undefined convert to NaN so they
always return false when compared to a different type" is not true. The
algorithms for type-converting comparison do not type-convert null and
undefined values at all, and no type-conversation would result in null
becoming NaN (it become zero if type-converted into numbers (and so
would be equal to zero if type-conversion was part of the comparison
process)).
The "Comparison is intuitive" comment when both sides of comparisons are
the same type does not take account of the fact that - NaN == NaN - is
false (and - NaN != NaN - true).
Richard.