[SOLVED] Is NaN equal to NaN?

Issue

parseFloat("NaN")

returns “NaN”, but

parseFloat("NaN") == "NaN"

returns false. Now, that’s probably a good thing that it does return false, but I don’t understand how this is so. Did the JavaScript creators just make this a special case? Because otherwise I can’t understand how this returns false.

Solution

When a JavaScript function returns NaN, this is not a literal string but an object property in the global space. You cannot compare it to the string "NaN".

See https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/NaN

Answered By – Phil

Answer Checked By – Marilyn (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.