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)