Fork me on GitHub

js中+new Data()

JavaScript中可以在某个元素前使用  '+'  号,这个操作是将该元素转换成Number类型,如果转换失败,那么将得到 NaN,

+new Date() 将会调用 Date.prototype 上的 valueOf() 方法,

根据MDN,Date.prototype.value方法等同于Date.prototype.getTime()

下面的代码效果相同:

 

    console.log(+new Date());
    console.log(new Date().getTime());
    console.log(new Date().valueOf());
    console.log(new Date() * 1);
posted @ 2020-09-14 14:19  xxzhang1437  阅读(889)  评论(0)    收藏  举报