Are +0 and -0 the same?

后端 未结 9 2094
花落未央
花落未央 2020-11-22 07:45

Reading through the ECMAScript 5.1 specification, +0 and -0 are distinguished.

Why then does +0 === -0 evaluate to true<

9条回答
  •  暖寄归人
    2020-11-22 08:13

    In the IEEE 754 standard used to represent the Number type in JavaScript, the sign is represented by a bit (a 1 indicates a negative number).

    As a result, there exists both a negative and a positive value for each representable number, including 0.

    This is why both -0 and +0 exist.

提交回复
热议问题