Reputation: 169383
Consider the following
var l = console.log.bind(console);
l(-0); // 0
l(0); // 0
l(0 === -0); // true
l(0 == -0); // true
l(1 / 0); // Infinity
l(1 / -0); // -Infinity
Bonus question:
0
/-0
combination the only combination where equal objects behave differently?I know NaN
/NaN
is a combination where non-equal objects behave the same.
Upvotes: 6
Views: 619
Reputation: 523224
Why is negative zero equal to zero ?
Because IEEE 754 demands it.
Is the
0
/-0
combination the only combination where equal objects behave differently?
I believe so. In Javascript, only Numbers have a special ===
algorithm, and 0, -0, NaN are the only special cases there (ECMA-262 §11.9.6).
Upvotes: 8