From the course: JavaScript: Best Practices for Functions and Classes

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Rely on implicit return only when obvious

Rely on implicit return only when obvious - JavaScript Tutorial

From the course: JavaScript: Best Practices for Functions and Classes

Start my 1-month free trial

Rely on implicit return only when obvious

- [Instructor] Arrow functions can let you write more compact code. And to further optimize that, they support leaving out some characters in some situations. With a single statement, you can omit the braces for the function block. You can omit the return statement altogether when returning a value is all the function does. And when you have a single parameter, you can even leave out the parentheses that normally enclose parameters. As with a lot of coding practices, there are trade-offs between making your arrow functions briefer and making them more understandable. ESLint lets you specify your preferred code style for arrow functions with a couple of rules. Arrow-parens governs when you want your code to include parentheses around parameters. Although you can leave them out for a single parameter, it's a good idea to use them consistently to make your code easier to read. Another ESLint rule, arrow-body-style lets you…

Contents