# JS Tip of the Day: Negative Zero

**URL:** <https://forum.kirupa.com/t/js-tip-of-the-day-negative-zero/643094>\
**Category:** web dev\
**Created:** [May 12, 2020, 2:25pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-negative-zero/643094 "2020-05-12T14:25:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 12, 2020, 2:25pm UTC](https://forum.kirupa.com/t/js-tip-of-the-day-negative-zero/643094/1 "2020-05-12T14:25:18Z")

</div>

**Negative Zero**  
Version ES2015 (Object.is)  
Level: Intermediate

Numbers in JavaScript are stored as double-precision values specified by the IEEE 754 standard. In this format, like every other number value, 0 can be negative. So just as you can have a 1 and a -1, so too can you have a 0 and a -0.

For the most part, 0 and -0 are equivalent. Numerically they have the same value, and if you attempt to compare them, even with strict equality, they’ll appear as equal.

```javascript
console.log(0 === -0); // true

```

There are only a few operations that will expose the difference of 0 and -0, such as dividing a number by 0. The result will be infinity, but depending on the sign of the 0, it could be negative or positive infinity.

```javascript
console.log(1/0); // Infinity
console.log(1/-0); // -Infinity

```

If you need to see if a 0 is negative or not, instead of using normal comparison, you can use `Object.is()` which can differentiate between 0 and -0.

```javascript
console.log(Object.is(0, 0)); // true
console.log(Object.is(-0, -0)); // true
console.log(Object.is(0, -0)); // false

```

You’ll only see negative 0 with regular number values in JavaScript. The other numeric type, BigInt, does not support them. A negative BigInt 0 is the same as a positive BigInt 0.

```javascript
console.log(Object.is(0n, -0n)); // true

```

More info:

- [Number on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- [IEEE 754 on Wikipedia](https://en.wikipedia.org/wiki/IEEE_754)
- [Object.is on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
- [BigInt on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)
