JS.BASE.NO.COMPARE.NEG.ZERO

Disallow comparing against -0

Rule Details

The rule should warn against code that tries to compare against -0, since that will not work as intended. That is, code like x === -0 will pass for both +0 and -0. The author probably intended Object.is(x, -0).

Examples of incorrect code for this rule:

Copy
/* eslint no-compare-neg-zero: "error" */

if (x === -0) {
    // doSomething()...
}

Examples of correct code for this rule:

Copy
/* eslint no-compare-neg-zero: "error" */

if (x === 0) {
    // doSomething()...
}
Copy
/* eslint no-compare-neg-zero: "error" */

if (Object.is(x, -0)) {
    // doSomething()...
}

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/