W3cubDocs

/ESLint

disallow comparing against -0 (no-compare-neg-zero)

The "extends": "eslint:recommended" property in a configuration file enables this rule.

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:


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

Examples of correct code for this rule:


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

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

Version

This rule was introduced in ESLint 3.17.0.

Resources

© JS Foundation and other contributors
Licensed under the MIT License.
https://eslint.org/docs/rules/no-compare-neg-zero