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

猜你喜欢

转载自www.cnblogs.com/yihengbaobei/p/12900892.html