-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
  • 53,718
  • 65
  • 205
  • 331

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
  • 356,069
  • 52
  • 309
  • 320