Skip to content

Commit dad2d80

Browse files
committed
fix precedence
1 parent fab3cdb commit dad2d80

File tree

1 file changed

+5
-7
lines changed
  • 1-js/02-first-steps/11-logical-operators

1 file changed

+5
-7
lines changed

1-js/02-first-steps/11-logical-operators/article.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,10 @@ When all values are truthy, the last value is returned:
230230
alert( 1 && 2 && 3 ); // 3, the last one
231231
```
232232
233-
````smart header="AND `&&` executes before OR `||`"
234-
The precedence of the AND `&&` operator is higher than OR `||`, so it executes before OR.
233+
````smart header="Precedence of AND `&&` is higher than OR `||`"
234+
The precedence of AND `&&` operator is higher than OR `||`.
235235
236-
In the code below `1 && 0` is calculated first:
237-
238-
```js run
239-
alert( 5 || 1 && 0 ); // 5
240-
```
236+
So the code `a && b || c && d` is essentially the same as if `&&` were in parentheses: `(a && b) || (c && d)`.
241237
````
242238
243239
Just like OR, the AND `&&` operator can sometimes replace `if`.
@@ -303,3 +299,5 @@ There's a little more verbose way to do the same thing -- a built-in `Boolean` f
303299
alert( Boolean("non-empty string") ); // true
304300
alert( Boolean(null) ); // false
305301
```
302+
303+
The precedence of NOT `!` is the highest of all bitwise operators, so it always executes first, before any `&&`, `||`.

0 commit comments

Comments
 (0)