+new Date是什么意思?

转载自http://blog.csdn.net/abxn2002/article/details/53420816

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

所以 +new Date 将会调用 Date.prototype 上的 valueOf 方法,而根据 MDN ,Date.prototype.value 方法等同于 Date.prototype.getTime() 。

所以下列代码效果相同:

  1. console.log(+new Date);  
  2.   
  3. console.log(new Date().getTime());  
  4.   
  5. console.log(new Date().valueOf());  
  6.   
  7. console.log(new Date() * 1);  
原文地址:https://www.cnblogs.com/rongyao/p/8126317.html