规则名 | 规则类型 |
---|---|
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()...
}