美文网首页
Js中的+new Date() 表示什么意思

Js中的+new Date() 表示什么意思

作者: 页面仔小杨 | 来源:发表于2017-09-08 10:28 被阅读0次

Js中的+new Date()

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);

相关文章

网友评论

      本文标题:Js中的+new Date() 表示什么意思

      本文链接:https://www.haomeiwen.com/subject/xrrgjxtx.html