Skip to content

Latest commit

 

History

History
52 lines (34 loc) · 842 Bytes

no-compare-neg-zero.md

File metadata and controls

52 lines (34 loc) · 842 Bytes
title layout edit_link rule_type
no-compare-neg-zero
doc
problem

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:

::: incorrect

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

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

:::

Examples of correct code for this rule:

::: correct

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

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

:::

::: correct

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

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

:::