Skip to main content
added 164 characters in body
Source Link
lonesomeday
  • 238.8k
  • 54
  • 330
  • 329

That is the unary plus operator. It attempts to convert the argument that follows into a number if it isn't already a number. The Date object implements a method that allows it to be converted to a number, which is the timestamp identical to the getTime() method.


A more legible and obvious way of getting a timestamp without using an extra variable is to use parentheses:

var timestamp = (new Date()).getTime(); 

That is the unary plus operator. It attempts to convert the argument that follows into a number if it isn't already a number. The Date object implements a method that allows it to be converted to a number, which is the timestamp identical to the getTime() method.

That is the unary plus operator. It attempts to convert the argument that follows into a number if it isn't already a number. The Date object implements a method that allows it to be converted to a number, which is the timestamp identical to the getTime() method.


A more legible and obvious way of getting a timestamp without using an extra variable is to use parentheses:

var timestamp = (new Date()).getTime(); 
Source Link
lonesomeday
  • 238.8k
  • 54
  • 330
  • 329

That is the unary plus operator. It attempts to convert the argument that follows into a number if it isn't already a number. The Date object implements a method that allows it to be converted to a number, which is the timestamp identical to the getTime() method.