add section 15.5 - Ternaries

add link to the relevant eslint rule
This commit is contained in:
Barry Gitarts
2016-01-11 17:54:35 -05:00
parent 7eb7b78513
commit d293e74872

View File

@@ -1246,6 +1246,29 @@ Other Style Guides
- [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.
- [15.5](#15.5) <a name='15.5'></a> Ternaries should not be nested and generally be single line expressions.
eslint rules: [`no-nested-ternary`](http://eslint.org/docs/rules/no-nested-ternary.html).
```javascript
//bad
const foo = maybe1 > maybe2
? "bar"
: value1 > value2 ? "baz" : null;
//better
const maybeNull = value1 > value2 ? 'baz' : null;
const foo = maybe1 > maybe2
? 'bar'
: maybeNull;
//best
const maybeNull = value1 > value2 ? 'baz' : null;
const foo = maybe1 > maybe2 ? 'bar' : maybeNull;
```
**[⬆ back to top](#table-of-contents)**