Why is ( Infinity | 0 ) === 0? Why is ( Infinity | 0 ) === 0? javascript javascript

Why is ( Infinity | 0 ) === 0?


Bitwise operators work on integers only.
Infinity is a floating-point value, not an integer.

The spec says that all operands of bitwise operations are converted to integers (using the ToInt32 operation) before performing the operation.

The ToInt32 operation says:

If number is NaN, +0, −0, +∞ or –∞ return +0.


Doing math and other operations that expect integers with NaN and Infinity is usually a bad idea. How would you set/clear a bit from Infinity?

Actually, bit-wise operations are only defined for integers - and integers do not have NaN or Infinity.