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
  • 16,564
  • 7
  • 51
  • 69
Shnick
  • 1,117
  • 6
  • 23

0 Answers0