Skip to content

A nice thing about zeroes in javascript #186

Answered by pero5ar
Pflyg asked this question in WTF Questions
Discussion options

You must be logged in to vote

Infinity == -Infinity does not surprise me because those are two different numbers on the extended real number line, so it's the same as doing 5 == -5.

The zero thing is neat. It's a thing defined by the standard for singed zero comparison. It makes sense in regards to that standard because the only difference between == and === should that === checks the type first and does not try to cast values, so values that are both numbers should get compared by value and not by notation (e.g. 1e1 === 10 is true).

That being said, I'm definitely in favour of adding the 0 === -0 example as that is a thing that people might get wrong about the === operator.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by denysdovhan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #155 on February 05, 2021 14:52.