]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/no-compare-neg-zero.md
import 8.23.1 source
[pve-eslint.git] / eslint / docs / src / rules / no-compare-neg-zero.md
1 ---
2 title: no-compare-neg-zero
3 layout: doc
4 rule_type: problem
5 ---
6
7
8
9 ## Rule Details
10
11 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)`.
12
13 Examples of **incorrect** code for this rule:
14
15 ::: incorrect
16
17 ```js
18 /* eslint no-compare-neg-zero: "error" */
19
20 if (x === -0) {
21 // doSomething()...
22 }
23 ```
24
25 :::
26
27 Examples of **correct** code for this rule:
28
29 ::: correct
30
31 ```js
32 /* eslint no-compare-neg-zero: "error" */
33
34 if (x === 0) {
35 // doSomething()...
36 }
37 ```
38
39 :::
40
41 ::: correct
42
43 ```js
44 /* eslint no-compare-neg-zero: "error" */
45
46 if (Object.is(x, -0)) {
47 // doSomething()...
48 }
49 ```
50
51 :::