A nice thing about zeroes in javascript #186
-
This weird behavior with strict comparisons and signed zeroes: var a = 0;
var b = -0;
(a === b); //true (0 === -0)
(1 / a) == (1 / b); //false (Infinity == -Infinity) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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 That being said, I'm definitely in favour of adding the |
Beta Was this translation helpful? Give feedback.
Infinity == -Infinity
does not surprise me because those are two different numbers on the extended real number line, so it's the same as doing5 == -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
istrue
).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.