Reports comparisons with -0 that may not behave as expected.
✅ This rule is included in the ts logical and logicalStrict presets.
In JavaScript, -0 and +0 are distinct values, but standard comparison operators (===, ==, !==, !=, <, <=, >, >=) treat them as equal.
This can lead to unexpected behavior when you need to distinguish between these values.
The Object.is() method correctly distinguishes between -0 and +0, making it the reliable choice when checking for negative zero.
AEfuncti5<3 sp ansty="le--0:#82AAFF;--1:#3B61">B0checkVal3 sp>1<1(sp ansty="le--0:#D7DBE0;--1:#403F">53val1(sp>7<2:sp ansty="le--0:#D6DEEB;--1:#403F">52:sp><3 sp ansty="le--0:#C5E478;--1:#3B61">B0numb3 sp>1<1)sp ansty="le--0:#D6DEEB;--1:#403F">531)sp>< {d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AE sp>53 (valuAE=<==sp ansty="le--0:#D6DEEB;--1:#403F">5==sp><3 sp ansty="le--0:#C792EA;--1:#8844">A3 sp>8<20sp ansty="le--0:#D6DEEB;--1:#403F">53)20sp> {d>< {d ivclassNa="meec-li">nt < sp ansty="le--0:#C792EA;--1:#8844">AEretu sp>5<3 sp ansty="le--0:#D9F5DD;--1:#1111">13 sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Dnegative ze1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">51"sp> {d><3;d ivclassNa="meec-li">53< sp ansty="le--0:#D6DEEB;--1:#403F">5 sp>3;d><3}d ivclassNa="meec-li">nt< sp ansty="le--0:#C792EA;--1:#8844">AEretu sp>5<3 sp ansty="le--0:#D9F5DD;--1:#1111">13 sp><1"sp ansty="le--0:#ECC48D;--1:#984E">4Doth1"sp>1<1"sp ansty="le--0:#D6DEEB;--1:#403F">51"sp>3}d><3;d ivclassNa="meec-li">53;d><3}d ivclassNa="meec-li">d3}d>76// Also incorrect with other operatoAE53 (valuAE<==sp ansty="le--0:#D6DEEB;--1:#403F">5==sp><3 sp ansty="le--0:#C792EA;--1:#8844">A3 sp>8<20sp ansty="le--0:#D6DEEB;--1:#403F">53)20sp>< {d ivclassNa="meec-li">5 {d><3}d ivclassNa="meec-li">AE53 (valuAE!<==sp ansty="le--0:#D6DEEB;--1:#403F">5==sp><3 sp ansty="le--0:#C792EA;--1:#8844">A3 sp>8<20sp ansty="le--0:#D6DEEB;--1:#403F">53)20sp>3}d>< {d ivclassNa="meec-li">5 {d><3}d ivclassNa="meec-li">AE53 (valuA5<3 sp ansty="le--0:#C792EA;--1:#8844">A3 sp>8<20sp ansty="le--0:#D6DEEB;--1:#403F">53)20sp>3}d>< {d ivclassNa="meec-li">5 {d><3}d ivclassNa="meec-li">AE53 (valuAE<>=sp ansty="le--0:#D6DEEB;--1:#403F">5>=sp><3 sp ansty="le--0:#C792EA;--1:#8844">A3 sp>8<20sp ansty="le--0:#D6DEEB;--1:#403F">53)20sp>3}d>< {d ivclassNa="meec-li">5 {d><3}d ivclassNa="meco">= -0) {"><}d>}d>3}d> 44AEfunc361B0checkV1<111( spans="tyle--0:#D7DBE0;--1:#40">3F53v111(>6361B0nu1<111) spans="tyle--0:#D6DEEB;--1:#40">3F111)><53 {divclass="Nameec-">de443F53 (Ob4<4AE. spans="tyle--0:#82AAFF;--1:#3B">614AE.>3F53(v6<67B, spans="tyle--0:#D6DEEB;--1:#40">367B,>4<4AE- spans="tyle--0:#F78C6C;--1:#AA">04AE-><9820 spans="tyle--0:#D6DEEB;--1:#40">3F539820>53 ><)) {divclass="Nameec-">dent< spans="tyle--0:#C792EA;--1:#88">44AEre >31<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dnegative 111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3111">)) >3F<53 spans="tyle--0:#D6DEEB;--1:#40">353 >de44AEre31<111" spans="tyle--0:#ECC48D;--1:#98">4E4Do111">1<111" spans="tyle--0:#D6DEEB;--1:#40">3111">3c6376// Regular zero comparisons are 443F53 (va44A30<9820 spans="tyle--0:#D6DEEB;--1:#40">3F59820><3) {divclass="Nameec-">33) >c6376// Negative one and other numbers are 443F53 (va44A34<4AE- spans="tyle--0:#F78C6C;--1:#AA">04AE-><9821 spans="tyle--0:#D6DEEB;--1:#40">3F59821><3) {divclass="Nameec-">33) >c6376// Using -0 in non-comparison contexts is 44AEco61B0negative44AE< = - spans="tyle--0:#F78C6C;--1:#AA">0 = -><9820 spans="tyle--0:#D6DEEB;--1:#40">39820>44AEco61B0re44AE< = - spans="tyle--0:#F78C6C;--1:#AA">0 = -><9820 spans="tyle--0:#C792EA;--1:#88">44A9820>0<9821 spans="tyle--0:#D6DEEB;--1:#40">39821><+ 1>+ 1>
This rule is not configurable.
If you never need to distinguish between -0 and +0 in your codebase, you might choose to disable this rule.
However, keeping it enabled helps prevent subtle bugs where the distinction matters, such as when working with mathematical calculations that produce negative zero (e.g., -1 / Infinity results in -0).