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.
Space after commas, but not before - JavaScript Tutorial
From the course: JavaScript: Best Practices for Code Formatting
Space after commas, but not before
- [Instructor] Commas separate values in JavaScript in a number of situations. It's common to write commas in code the same way you would use them in a sentence, with no space before and a space after. However, other comma styles are used as well, including a space before but no space after or no spaces on either side. I use a space only after commas, and so far, I've been writing my ESLintRC file using that format. I want to add a rule to flag errors if my spacing deviates. ESLint supports the comma spacing rule, which lets me specify which style I want to use and how I want it flagged. So over in my ESLintRC file I'm going to add a new line, and that's going to be comma-spacing and in an array, I going to specify that I want it to be flagged as an error, and then I need an object literal. I'm going to specify the value before with a value of false, and a value of after, and give that a value of true. Got to make sure…
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
-
-