no-compare-neg-zero
JavaScript / TypeScriptsuspiciousno fixdefault: warnjs/eslint-recommendedjs/biome-recommendedjs/oxlint
What it does
Section titled “What it does”Reports a comparison with -0 on either side of ==, !=, ===, !==, <, <=, > or >=. Object.is(x, -0) and a comparison with +0 are not reported.
Why it matters
Section titled “Why it matters”-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.
Example
Section titled “Example”...if (x === -0) {} if (-0 < x) {} if (x === +0) {} if (x + -0 === y) {}Configuration
Section titled “Configuration”js: lint: rules: no-compare-neg-zero: warn # off, warn (default), errorEnabled 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.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| eslint | no-compare-neg-zero |
full |