Differentiating +0 and −0 区分 +0 和 −0

20 浏览
0 Comments

Differentiating +0 and −0 区分 +0 和 −0

原来,尽管+0和-0是不同的实体,但+0 === -0的结果是true。那么,如何区分+0和-0呢?

有一个技巧:

if (1 / myZero > 0) {
   // myZero是+0
} else {
   // myZero是-0
}

我能做得更好吗?

0