DEV Community

sunflowerseed
sunflowerseed

Posted on • Updated on

The only two values a and b 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.

The results are not just different, but very different.

Top comments (0)