Javascript – What does the plus sign do in ‘+new Date’


I've seen this in a few places

function fn() {
    return +new Date;

And I can see that it is returning a timestamp rather than a date object, but I can't find any documentation on what the plus sign is doing.

Can anyone explain?

Best Answer

that's the + unary operator, it's equivalent to:

function(){ return Number(new Date); }


and in MDN: