+ 1

Why when compare NaN it return always false ?

var n1 = 5 * "hossam"; var n2 = 5 * "hossam"; console.log(n1 === n2); //false console.log(n1 == n2); // false Why ???

10th Feb 2019, 10:11 AM
Hossam Hassan
Hossam Hassan - avatar
4 Antworten
+ 5
In terms of accepting NaN != NaN, something which is not a number is not necessarily equivalent to something else which also isn't a number. All in all, like Jomari pointed out, NaN is just designed to fail the equality test since NaN does not refer to anything specific.
10th Feb 2019, 11:32 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
That's just the way how it was configured. NaN will fail every equality check to any value including to itself.
10th Feb 2019, 10:35 AM
Jomari Pantorilla
Jomari Pantorilla - avatar
+ 1
I won't use it for compare but all what I want know is what behind seen ? ... for ex: int x = new Int(5); Int y = new Int(5); Both not equal coz different in memory address ... etc
10th Feb 2019, 12:24 PM
Hossam Hassan
Hossam Hassan - avatar