I was looking at this question about how to efficiently check if a value is an integer. One answer recommended using n === (n|0)
for some quick rounding via the |
operator. On a whim, I decided to test it with Number.MAX_VALUE
. Despite the fact that this should be an integer (I think?), the test came back false.
It also came back false for Number.MAX_SAFE_INTEGER
, so I decided to test some other large numbers and found the following:
Number.MAX_VALUE | 0 --> 0
Number.MAX_SAFE_INTEGER | 0 --> -1
Number.MAX_SAFE_INTEGER/2 | 0 --> -1
Number.MAX_SAFE_INTEGER/8 | 0 --> -1
1234567890 | 0 --> 1234567890
I'm not really sure what the |
operator is doing internally, but it doesn't seem safe to do on MAX_SAFE_INTEGER
. Why is that the case?