From d293e748725ee16fb1a96afd80b005c60e2781a0 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Mon, 11 Jan 2016 17:54:35 -0500 Subject: [PATCH] add section 15.5 - Ternaries add link to the relevant eslint rule --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index a0f492a93a..da96b7979b 100644 --- a/README.md +++ b/README.md @@ -1246,6 +1246,29 @@ Other Style Guides - [15.4](#15.4) 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) 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)**