isNaN() returns true with imaginary numbers (like square and even roots of negative numbers).
// Extract a square root with the Math.sqrt() method:
alert( Math.sqrt(-5).toString() );
Since the NaN property cannot be equated to anything else (even itself), only the isNaN() function can check for unexpected numerical results. As illustration, the code below returns false on both counts.
// Identity operator
alert( Number.NaN === Number.NaN );
// Equality operator
alert( Number.NaN == Number.NaN );
Using the derived isNaN() function, however, we obtain expected results:
// The isNaN() function returns true
alert( isNaN(Number.NaN) );
// Once more, isNaN() returns true
alert( isNaN(Math.sqrt(-5)) );
Test the Number NaN Property