From the course: JavaScript: Best Practices for Code Formatting
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Solution: Optimize spacing - JavaScript Tutorial
From the course: JavaScript: Best Practices for Code Formatting
Solution: Optimize spacing
(upbeat music) - [Instructor] In my Challenge file, I'm starting with my .eslint file, and now I notice already in my script.js file, I have an error, and that's due to a really long line down here, clearly this is a bunch of chained methods and we're going to get to that, so we'll just leave that be for the moment. So I'm going to go one by one with my rules, adding the rules that deal with spacing, and then using the prompts from ESLint to identify and fix issues in my files. So first off is the indent rule, and I want to flag an error when that's not two, so I'll save that, back in my script.js file, I can see up here, I have some right-aligned elements in an array, and I want those to be left-aligned, so I'm going to take out spaces until those all line up at two spaces, and now I'm back to one which is still that really long line, so I'm good with the indents. Next up, I'm going to specify space around my infix…
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
-
-
-
-
-
-
Indent consistently5m 54s
-
Space before and after operators3m 23s
-
Use a consistent format for blocks3m 58s
-
Include a space after keywords and arrows3m 2s
-
Use consistent spacing before function signature parentheses3m 37s
-
Break up and indent long-method chains2m 46s
-
Space consistently within enclosing characters7m 58s
-
Space after commas, but not before2m 14s
-
Limit blank space to one line2m 50s
-
Challenge: Optimize spacing30s
-
Solution: Optimize spacing10m 29s
-
-