From the course: JavaScript: Best Practices for Code Formatting

Unlock the full course today

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

Break up and indent long-method chains

Break up and indent long-method chains - JavaScript Tutorial

From the course: JavaScript: Best Practices for Code Formatting

Start my 1-month free trial

Break up and indent long-method chains

- [Instructor] Chaining methods together enables you to write compact code that accomplishes a task without unnecessary reassignment, however, the trade off for that compactness can be dense code that's hard to read. To make long method chains more legible, it's useful to break them up onto multiple lines with a dot preceding a method name starting a new line, combined with indenting the methods below the first line of the statement. This format makes it easy to understand the sequence of modifications being applied, as well as where the chain begins and ends. ESLint includes the newline-per-chained-call rule which flags errors in your code if your methods aren't on their own lines. In my app that identifies points of interest based on a user's location, I'm building a fetch request to the US Park's Service API to get information on national parks. Notice that I already have one error here, and that's just because I have a…

Contents