Skip to content

no-compare-neg-zero

Reports a comparison with -0 on either side of ==, !=, ===, !==, <, <=, > or >=. Object.is(x, -0) and a comparison with +0 are not reported.

-0 and 0 are different values but compare as equal: 0 === -0 is true. So x === -0 is also true for plain zero, and the check does not do what it reads like.

To fix, use Object.is(x, -0), which tells them apart.

Reported
...
if (x === -0) {} if (-0 < x) {} if (x === +0) {} if (x + -0 === y) {}
js:
lint:
rules:
no-compare-neg-zero: warn # off, warn (default), error

Enabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint.

Suppress one line with sudsy-disable-next-line no-compare-neg-zero in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint no-compare-neg-zero full