What does +new Date() mean

js uses ‘+’ before a data type. The purpose of this operation is to convert the data type to Number type. If the conversion fails, it will return NaN;

E.g:

 + '2' + 1 // 3 + [ 1 ] // NaN

+new Date() will call the valueOf method on Date.prototype, according to

new Date().getTime() === new Date().valueOf() //true

The following example returns the same effect:

 console . log ( + new Date ( ) ) ; console . log

The post What does +new Date() mean first appeared on Lenix Blog .

This article is reprinted from https://blog.p2hp.com/archives/9271
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment