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?
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With