no-compare-neg-zero
Disallow comparing against -0
error by defaulthas suggestions
0 and -0 compare as equal, so x === -0 is also true when x is 0. The minus sign has no effect.
To tell the two apart, use Object.is(x, -0). Otherwise compare with 0.
This rule is on by default.
Configure#
On by default as an error. To turn it off:
bunfig.toml
[lint.rules]
"no-compare-neg-zero" = "off" # or "warn"Examples#
example.js1 problem
if (offset === -0Do not use the === operator to compare against -0.) {
flipDirection();
}example.jsNo problems
if (Object.is(offset, -0)) {
flipDirection();
}
if (offset === 0) {
stop();
}<, <=, > and >= are reported too:
example.js1 problem
const isForward = speed >= -0Do not use the >= operator to compare against -0.;