0

Here are two cases:

console.log(Math.abs(-16) % 2 === 0) //true
console.log(Math.abs(-16) % 2 === -0) //true

In the second case, isn't Math.abs() supposed to change -16 into 16, therefore making it return false because 16 % 2 !== -0? Also how can i solve it so that the second case (console.log(Math.abs(-16) % 2 === -0)) doesn't return true, instead, false

1 Answers1

1

You need Object.is if you want to tell the difference between positive and negative zeroes:

console.log(Object.is(-16 % 2, +0)) // false
console.log(Object.is(-16 % 2, -0)) // true
gog
  • 10,367
  • 2
  • 24
  • 38