DEV Community

sunflowerseed
sunflowerseed

Posted on • Edited on

The only two values in JavaScript that is a === b, but operation using them give different results

This is the quiz for today...

a === b gives true
yet if you use them for the same operation, they give different results.

What are they?

The answer is...

Scroll down to see it...

Or do you want more times to think about it.

It is not a trick question.

And the answer is

const a = 0, b = -0;

console.log(a === b);   // gives true
Enter fullscreen mode Exit fullscreen mode

but 1 / a and 1 / b give different results.
The first one is Infinity. The second one is -Infinity.

Top comments (0)