up
This commit is contained in:
parent
83b93e5992
commit
9ad9063d00
742 changed files with 884 additions and 779 deletions
|
@ -0,0 +1,9 @@
|
|||
|
||||
|
||||
```js
|
||||
let message = (login == 'Employee') ? 'Hello' :
|
||||
(login == 'Director') ? 'Greetings' :
|
||||
(login == '') ? 'No login' :
|
||||
'';
|
||||
```
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
importance: 5
|
||||
|
||||
---
|
||||
|
||||
# Rewrite 'if..else' into '?'
|
||||
|
||||
Rewrite `if..else` using multiple ternary operators `'?'`.
|
||||
|
||||
For readability, it's recommended to split the code span over lines.
|
||||
|
||||
```js
|
||||
let message;
|
||||
|
||||
if (login == 'Employee') {
|
||||
message = 'Hello';
|
||||
} else if (login == 'Director') {
|
||||
message = 'Greetings';
|
||||
} else if (login == '') {
|
||||
message = 'No login';
|
||||
} else {
|
||||
message = '';
|
||||
}
|
||||
```
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue