Why does ~~Infinity return 0?

68 Views Asked by At

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)

0

There are 0 best solutions below