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


i've seen in few places

function fn() {     return +new date; } 

and can see returning timestamp rather date object, can't find documentation on plus sign doing.

can explain?

that's + 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


Comments

Popular posts from this blog

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

c++ - How do I get a multi line tooltip in MFC -

unit testing - How to mock PreferenceManager in Android? -