How does 5.5 | 0 === 5
work?
Is | 0
in this context the bitwise OR
I suspect it to be? If so, why does it cut off everything after the point?
Bitwise operators always coerce operands to 32-bit integers.
The operation is interpreted as
5.5 | (0 === 5)
which is
5.5 | false
which is coerced to
5.5 | 0
Now the 5.5
is converted to a 32-bit integer, so we have
5 | 0
which is 5
.
The relational operators bind more tightly than the bitwise operators which can be confusing. If you want to compare the result of a bitwise operator (unlike, say, an addition or multiplication), you have to parenthesize explicitly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With