Skip to content

Commit c72528f

Browse files
committed
add section 15.5 - Ternaries
add link to the relevant eslint rule
1 parent af81beb commit c72528f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,29 @@ Other Style Guides
12891289
12901290
- [15.4](#15.4) <a name='15.4'></a> For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll.
12911291
1292+
- [15.5](#15.5) <a name='15.5'></a> Ternaries should not be nested and generally be single line expressions.
1293+
1294+
eslint rules: [`no-nested-ternary`](http://eslint.org/docs/rules/no-nested-ternary.html).
1295+
1296+
```javascript
1297+
//bad
1298+
const foo = maybe1 > maybe2
1299+
? "bar"
1300+
: value1 > value2 ? "baz" : null;
1301+
1302+
//better
1303+
const maybeNull = value1 > value2 ? 'baz' : null;
1304+
1305+
const foo = maybe1 > maybe2
1306+
? 'bar'
1307+
: maybeNull;
1308+
1309+
//best
1310+
const maybeNull = value1 > value2 ? 'baz' : null;
1311+
1312+
const foo = maybe1 > maybe2 ? 'bar' : maybeNull;
1313+
```
1314+
12921315
**[⬆ back to top](#table-of-contents)**
12931316
12941317

0 commit comments

Comments
 (0)