加号在'+新日期'中的作用是什么 [英] What does the plus sign do in '+new Date'

查看:126
本文介绍了加号在'+新日期'中的作用是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一些地方看到了这个

function fn() {
    return +new Date;
}

我可以看到它返回时间戳而不是日期对象,但我找不到加号正在做什么的任何文件。

And I can see that it is returning a timestamp rather than a date object, but I can't find any documentation on what the plus sign is doing.

任何人都可以解释一下吗?

Can anyone explain?

推荐答案

这是+一元运算符,相当于:

that's the + unary operator, it's equivalent to:

function(){ return Number(new Date); }

参见:
http://xkr.us/articles/javascript/unary-add/

和在MDN中: https://developer.mozilla。 org / zh-CN / docs / Web / JavaScript / Reference / Operators / Arithmetic_Operators#Unary_plus

这篇关于加号在'+新日期'中的作用是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆