Reputation: 3765
var a = 0;
var b = -a;
When I post the following code to console I got true
:
console.log(a === b); // true
But when I do some calculation with it I got false
:
console.log(1/a === 1/b); // false
Why is it so?
Upvotes: 7
Views: 144
Reputation: 67207
That is because Infinity == -Infinity
is false, as per abstract equality comparison algorithm.
1/0
will yield Infinity
at the same time 1/-0
Yields -Infinity
. So both are not are not equal and thus returning false
.
Upvotes: 7