Julian Hollmann Julian Hollmann - 4 months ago 7x
Javascript Question

+new Date() - Is this good practice?

So we had the Discussion today in our company about

+new Date()
being good practice or not.
Some prefer this way over
new Date().getTime()

In my opinion, this is pretty convenient but on the other side one would say it's harder to read.

Are there any pros or cons besides the obvious "It's harder to understand for people not familiar with the unary operator"?


After thinking about this the last years a lot I came to the conclusion that performance is not a factor here.

So here is the solution I prefer in terms of readability: