Why Date.now() | 0 not same as Date.now()

bluelovers :

Int Number | 0 will same as source number

But why Date.now() | 0 not same as Date.now()

let t = Date.now()
console.log((t | 0) === t)

CertainPerformance :

Bitwise operators operate on bits as represented by 32 zeros and/or ones. If the number being operated on is outside this range, the result will likely be unintuitive.

For bitwise OR, this limit is reached once the number is 2 ** 31 - 1:

const test = num => console.log((num | 0) === num);
test(2 ** 31 - 1)
test(2 ** 31)
test(2 ** 31 + 1)

Date.now returns the number of milliseconds between the epoch and now, which is a large number (1583486012561 or thereabouts), much larger than the upper limit of 2147483647.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=29653&siteId=1