In order to take the Timestamps in javascript yuo can write this kind of code:
// Usual Way
var d = new Date();
timestamp = d.getTime();
But I found that is it also possible to get the same result in this way:
// The shortest Way
timestamp = +new Date();
Can someone help me to understand how the Shortest Way works?
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
Dateobject implements a method that allows it to be converted to a number, which is the timestamp identical to thegetTime()method.A more legible and obvious way of getting a timestamp without using an extra variable is to use parentheses: