You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If all variables were falsy,`Anonymous` would show up.
118
+
如果所有变量都为假(falsy),结果就是`Anonymous`。
119
119
120
-
2.**Short-circuit evaluation.**
120
+
2.**短路求值(Short-circuit evaluation)。**
121
121
122
-
Another feature ofOR`||`operator is the so-called "short-circuit" evaluation.
122
+
或运算符 `||`的另一个特点是所谓的“短路求值”。
123
123
124
-
It means that `||`processes its arguments until the first truthy value is reached, and then the value is returned immediately, without even touching the other argument.
124
+
它的意思是,`||`对其参数进行处理,直到达到第一个真值,然后立即返回该值,而无需处理其他参数。
125
125
126
-
That importance ofthis feature becomes obvious if an operand isn't just a value, but an expression with a side effect, such as a variable assignment or a function call.
所以代码 `a && b || c && d` 完全跟 `&&` 表达式加了括号一样:`(a && b) || (c && d)`。
224
224
````
225
225
226
-
````warn header="Don't replace `if` with || or &&"
227
-
Sometimes, people use the AND`&&`operator as a "shorter to write `if`".
226
+
````warn header="不要用 || 或 && 来取代 `if`"
227
+
有时候,有人会用与运算符 `&&`来“简化 `if`”。
228
228
229
229
例如:
230
230
@@ -244,7 +244,7 @@ let x = 1;
244
244
if (x > 0) alert( 'Greater than zero!' );
245
245
```
246
246
247
-
Although, the variant with`&&`appears shorter, `if`is more obvious and tends to be a little bit more readable. So we recommend using every construct for its purpose: use `if`if we want if and use `&&`if we want AND.
0 commit comments