3

Recently I have been playing around with the double bitwise not (~~) operator in JavaScript.

I noticed that ~~Infinity returns 0. Why is this?

I would expect it to return Infinity, similarly to how Math.trunc(Infinity) returns Infinity and not 0.

console.log(~~Infinity) // 0? Expected Infinity
console.log(Math.trunc(Infinity)); // Infinity (as expected)
Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
Shnick
  • 1,199
  • 1
  • 13
  • 32

0 Answers0