Why is 0 === -0 true, but 1/0 === 1 / -0 false?

var a = 0; var b = -a; 

When I send the following code to the console, I got true :

 console.log(a === b); // true 

But when I do calculations with it, I got false :

 console.log(1/a === 1/b); // false 

Why is this so?

+6
source share
1 answer

This is because Infinity == -Infinity is false, according to the abstract equality comparison algorithm.

1/0 will give Infinity at the same time 1/-0 Allows -Infinity . Thus, both parameters are not equal and thus return false .

+7
source

All Articles