var a = 0; var b = -a;
When I send the following code to the console, I got true :
true
console.log(a === b); // true
But when I do calculations with it, I got false :
false
console.log(1/a === 1/b); // false
Why is this so?
This is because Infinity == -Infinity is false, according to the abstract equality comparison algorithm.
Infinity == -Infinity
1/0 will give Infinity at the same time 1/-0 Allows -Infinity . Thus, both parameters are not equal and thus return false .
1/0
Infinity
1/-0
-Infinity