What is the difference between
new Date().valueOf()
and
new Date() * 1
Both give the same value, is there any performance difference? (Just out of curiosity)
Using an object in a multiplication expression implicitly involves a call to .valueOf() anyway, so there's really no difference at all. That is, the way that the expression
new Date() * 1
is interpreted involves an attempt to get the operand on the left side of the * operator to be a number. That's what the .valueOf() method is supposed to do. For Date instances, that returns the millisecond timestamp value.
Note that
Date.now()
is also equivalent. (Not new Date().now(); the "now" function is a property of the Date constructor.)
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