请问这是什么意思:if (a && b == c){};?

Please what does mean this : if (a && b == c){};?

请问这是什么意思:

if (a && b == c){};

没看懂条件语句的逻辑

&& 的优先级低于 ==,所以它等价于:

if (a && (b == c))

表示如果a有一个真值并且b的值等于c的值。

条件(a && b == c)有两个operators. The Logical AND Operator and the Equality Operator.

操作 foo && bar returns 为真,如果两个操作数 foobar 都有 truthy 值。

foo == bar returns 正确,如果 foo 等于 bar.

The equality operator converts the operands if they are not of the same type, then applies strict comparison. If both operands are objects, then JavaScript compares internal references which are equal when operands refer to the same object in memory.

如果表达式包含多个运算符,则 operator precedence 最为重要。

Operator precedence determines the way in which operators are parsed with respect to each other. Operators with higher precedence become the operands of operators with lower precedence.

== 运算符的优先级高于 && 运算符。因此,上述条件将首先检查 b == c。如果结果为 truea 的值为真,则条件的结果将为 true.

分组运算符 ( ) 具有最高优先级,因此可用于强制执行特定的操作顺序。

如果您不确定操作的处理顺序,请使用分组运算符!

结果

(a && (b == c)) 

将与

的结果相同
(a && b == c)

但可读性更好。当然,您应该学习并了解运算符的优先级。但是,如果有疑问,尤其是在有很多运算符的非常复杂的行中,几个括号增加可读性的价值很容易超过一些额外代码的成本。