什么和&&在javascript表达式中返回 [英] what does && return in javascript expression

查看:98
本文介绍了什么和&&在javascript表达式中返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读某些应用程序中的javascipt代码,代码是这个

I was reading the javascipt code in some application and code was this

getTotalFees:function(){
        return this.grid
        &&this.grid.getStore().sum('fees');
}

现在我很困惑它将返回什么。

Now i am confused what it will return.

IT对我来说就像

返回&& b

不会返回true或false而不是b

won't it return true or false rather than b

推荐答案


逻辑AND(&& ):

expr1&& expr2 如果可以转换为false,则返回 expr1 ;否则,返回 expr2 。因此,当与布尔值一起使用时,如果两个操作数都是&& 将返回 true ;否则,返回 false

Logical AND (&&):
expr1 && expr2 Returns expr1 if it can be converted to false; otherwise, returns expr2. Thus, when used with Boolean values, && returns true if both operands are true; otherwise, returns false.

来源

所以,基本上:

如果第一个参数是 falsy ,它会返回该参数。否则,它确实返回第二个参数。

So, basically:
If the first parameter is falsy, it returns that parameter. Else, it literally returns the second parameter.

在您的情况下,这意味着,如果 this.grid 存在,它返回 this.grid.getStore()。sum('fees');

In your case, this means that, if this.grid exists, it returns this.grid.getStore().sum('fees');

这篇关于什么和&&在javascript表达式中返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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