Can anyone explain why this line is used in lodash library.
if (!value) {
return value === 0 ? value : 0;
}
and why not just return 0;
There are two different values which are considered strictly equal to zero: +0
and -0
:
+0 === +0;
+0 === -0;
-0 === +0;
-0 === -0;
However, these values don't behave completely identically:
1 / +0 === +Infinity
1 / -0 === -Infinity
and clearly +Infinity !== -Infinity
.
Then the code does this:
value
is "falsy" (undefined
, null
, false
, +0
, -0
, NaN
, ""
)
value
is +0
or -0
, it returns value
+0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With