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

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:

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

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

Examples of correct code for this rule:

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

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

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

Version

This rule was introduced in ESLint 3.17.0.

Resources

Js中文网,专注分享前端最新技术、大厂面试题、聊点程序员轶事、职场感悟,做前端技术的传播者.

加入前端布道师交流群

扫描二维码回复 加群 学习,与大厂大佬讨论技术.

BAT面试题大全