fix precedence
This commit is contained in:
parent
fab3cdbfef
commit
dad2d807de
1 changed files with 5 additions and 7 deletions
|
@ -230,14 +230,10 @@ When all values are truthy, the last value is returned:
|
||||||
alert( 1 && 2 && 3 ); // 3, the last one
|
alert( 1 && 2 && 3 ); // 3, the last one
|
||||||
```
|
```
|
||||||
|
|
||||||
````smart header="AND `&&` executes before OR `||`"
|
````smart header="Precedence of AND `&&` is higher than OR `||`"
|
||||||
The precedence of the AND `&&` operator is higher than OR `||`, so it executes before OR.
|
The precedence of AND `&&` operator is higher than OR `||`.
|
||||||
|
|
||||||
In the code below `1 && 0` is calculated first:
|
So the code `a && b || c && d` is essentially the same as if `&&` were in parentheses: `(a && b) || (c && d)`.
|
||||||
|
|
||||||
```js run
|
|
||||||
alert( 5 || 1 && 0 ); // 5
|
|
||||||
```
|
|
||||||
````
|
````
|
||||||
|
|
||||||
Just like OR, the AND `&&` operator can sometimes replace `if`.
|
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
|
||||||
alert( Boolean("non-empty string") ); // true
|
alert( Boolean("non-empty string") ); // true
|
||||||
alert( Boolean(null) ); // false
|
alert( Boolean(null) ); // false
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The precedence of NOT `!` is the highest of all bitwise operators, so it always executes first, before any `&&`, `||`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue