-2

The strict equality operator identifies 0 and -0 as being equal.

console.log(0 === -0) // true

... so is Math.sign the only way to distinguish these values?

Ben Aston
  • 49,455
  • 61
  • 188
  • 322

1 Answers1

2

You can also use Object.is:

const num1 = 0;
const num2 = -0;
console.log(Object.is(num1, num2));
console.log(Object.is(num1, num1));
CertainPerformance
  • 313,535
  • 40
  • 245
  • 254