diff --git a/README.md b/README.md index 7aa0062a7e..cebc053bcc 100644 --- a/README.md +++ b/README.md @@ -699,7 +699,7 @@ Other Style Guides }); ``` - - [8.2](#8.2) If the function body consists of a single expression, feel free to omit the braces and use the implicit return. Otherwise use a `return` statement. + - [8.2](#8.2) If the function body consists of a single expression, omit the braces and use the implicit return. Otherwise, keep the braces and use a `return` statement. > Why? Syntactic sugar. It reads well when multiple functions are chained together. @@ -743,18 +743,36 @@ Other Style Guides ``` - - [8.4](#8.4) If your function only takes a single argument, feel free to omit the parentheses. + - [8.4](#8.4) If your function takes a single argument and doesn’t use braces, omit the parentheses. Otherwise, always include parentheses around arguments. > Why? Less visual clutter. eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html). ```js + // bad + [1, 2, 3].map((x) => x * x); + // good [1, 2, 3].map(x => x * x); // good - [1, 2, 3].reduce((y, x) => x + y); + [1, 2, 3].map(number => ( + `A long string with the ${number}. It’s so long that we’ve broken it ` + + 'over multiple lines!' + )); + + // bad + [1, 2, 3].map(x => { + const y = x + 1; + return x * y; + }); + + // good + [1, 2, 3].map((x) => { + const y = x + 1; + return x * y; + }); ``` **[⬆ back to top](#table-of-contents)**