在变量之前加号的目的是什么? [英] What is the purpose of a plus symbol before a variable?
本文介绍了在变量之前加号的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这听起来像一个简单的问题,但我没有运气搜索。什么 + d
this really sounds like a simple question but I had no luck searching. what does the +d
in
function addMonths(d, n, keepTime) {
if (+d) {
是什么意思?
推荐答案
+运算符返回对象的数字表示。因此,在您的特定情况下,它似乎是在判断d是否为非零数字。
The + operator returns the numeric representation of the object. So in your particular case, it would appear to be predicating the if on whether or not d is a non-zero number.
Reference here. And, as pointed out in comments, here.
这篇关于在变量之前加号的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文