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 - JavaScript Tutorial
From the course: JavaScript: Best Practices for Code Formatting
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Indent consistently5m 54s
-
(Locked)
Space before and after operators3m 23s
-
(Locked)
Use a consistent format for blocks3m 58s
-
(Locked)
Include a space after keywords and arrows3m 2s
-
(Locked)
Use consistent spacing before function signature parentheses3m 37s
-
(Locked)
Break up and indent long-method chains2m 46s
-
(Locked)
Space consistently within enclosing characters7m 58s
-
(Locked)
Space after commas, but not before2m 14s
-
(Locked)
Limit blank space to one line2m 50s
-
(Locked)
Challenge: Optimize spacing30s
-
(Locked)
Solution: Optimize spacing10m 29s
-
(Locked)
-