DEV Community

sunflowerseed
sunflowerseed

Posted on • Edited on

2 2

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)

AWS Q Developer image

Build your favorite retro game with Amazon Q Developer CLI in the Challenge & win a T-shirt!

Feeling nostalgic? Build Games Challenge is your chance to recreate your favorite retro arcade style game using Amazon Q Developer’s agentic coding experience in the command line interface, Q Developer CLI.

Participate Now

👋 Kindness is contagious

Sign in to DEV to enjoy its full potential—unlock a customized interface with dark mode, personal reading preferences, and more.

Okay