Address some possible issues in 1.2.11
This commit is contained in:
parent
e074a5f825
commit
64f3015dfd
4 changed files with 12 additions and 12 deletions
|
@ -84,7 +84,7 @@ The OR `||` operator does the following:
|
|||
|
||||
A value is returned in its original form, without the conversion.
|
||||
|
||||
In other words, a chain of OR `"||"` returns the first truthy value or the last one if no truthy value is found.
|
||||
In other words, a chain of OR `||` returns the first truthy value or the last one if no truthy value is found.
|
||||
|
||||
For instance:
|
||||
|
||||
|
@ -101,9 +101,9 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl
|
|||
|
||||
1. **Getting the first truthy value from a list of variables or expressions.**
|
||||
|
||||
For instance, we have `firstName`, `lastName` and `nickName` variables, all optional.
|
||||
For instance, we have `firstName`, `lastName` and `nickName` variables, all optional (i.e. can be undefined or have falsy values).
|
||||
|
||||
Let's use OR `||` to choose the one that has the data and show it (or `anonymous` if nothing set):
|
||||
Let's use OR `||` to choose the one that has the data and show it (or `"Anonymous"` if nothing set):
|
||||
|
||||
```js run
|
||||
let firstName = "";
|
||||
|
@ -115,7 +115,7 @@ This leads to some interesting usage compared to a "pure, classical, boolean-onl
|
|||
*/!*
|
||||
```
|
||||
|
||||
If all variables were falsy, `Anonymous` would show up.
|
||||
If all variables were falsy, `"Anonymous"` would show up.
|
||||
|
||||
2. **Short-circuit evaluation.**
|
||||
|
||||
|
@ -223,7 +223,7 @@ The precedence of AND `&&` operator is higher than OR `||`.
|
|||
So the code `a && b || c && d` is essentially the same as if the `&&` expressions were in parentheses: `(a && b) || (c && d)`.
|
||||
````
|
||||
|
||||
````warn header="Don't replace `if` with || or &&"
|
||||
````warn header="Don't replace `if` with `||` or `&&`"
|
||||
Sometimes, people use the AND `&&` operator as a "shorter way to write `if`".
|
||||
|
||||
For instance:
|
||||
|
@ -244,7 +244,7 @@ let x = 1;
|
|||
if (x > 0) alert( 'Greater than zero!' );
|
||||
```
|
||||
|
||||
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.
|
||||
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.
|
||||
````
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue