What does the plus sign do in '+new Date'

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

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

see: http://xkr.us/articles/javascript/unary-add/

and in MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Unary_plus


JavaScript is loosely typed, so it performs type coercion/conversion in certain circumstances:

http://blog.jeremymartin.name/2008/03/understanding-loose-typing-in.html
http://www.jibbering.com/faq/faq_notes/type_convert.html

Other examples:

>>> +new Date()
1224589625406
>>> +"3"
3
>>> +true
1
>>> 3 == "3"
true

Here is the specification regarding the "unary add" operator. Hope it helps...


A JavaScript date can be written as a string:

Thu Sep 10 2015 12:02:54 GMT+0530 (IST)

or as a number:

1441866774938

Dates written as numbers, specifies the number of milliseconds since January 1, 1970, 00:00:00.

Coming to your question it seams that by adding '+' after assignment operator '=' , converting Date to equal number value.

same can be achieve using Number() function, like Number(new Date());

var date = +new Date(); //same as 'var date =number(new Date());'