Skip to content

Latest commit

 

History

History
44 lines (28 loc) · 707 Bytes

no-compare-neg-zero.md

File metadata and controls

44 lines (28 loc) · 707 Bytes
规则名 规则类型
no-compare-neg-zero
problem

规则详解

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).

此规则的 错误 代码实例:

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

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

此规则的 正确 代码实例:

::: correct

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

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

::: correct

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

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