What is the difference between new Date and +new Date?
For example:
var date = new Date;
console.log(date);
var plusDate = +new Date;
console.log(plusDate);
Logs:
Sat May 10 2014 01:13:46 GMT+0300 (Jordan Standard Time)
1399673626539
What is the difference between new Date and +new Date?
For example:
var date = new Date;
console.log(date);
var plusDate = +new Date;
console.log(plusDate);
Logs:
Sat May 10 2014 01:13:46 GMT+0300 (Jordan Standard Time)
1399673626539
The unary plus operator casts the Date object to a Number object (which is expressed in in milliseconds since 01 January, 1970 UTC).
The first one creates a Date object, the second one adds the current date value in milliseconds to the original value of plusDate, which was 0.