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.
Include a space after keywords and arrows - JavaScript Tutorial
From the course: JavaScript: Best Practices for Code Formatting
Include a space after keywords and arrows
- Including spaces around keywords like function and if can make your JavaScript code more readable. The same is true for spaces around arrows in arrow functions. ESLint includes a keyword spacing rule that lets your specify the format to check for keywords. ESLint also includes an arrow spacing rule that's specific to the arrows in arrow functions. My app.js file contains an arrow function, which includes if else logic. And right now, that's written without spaces before or after the if, else if, or else keywords, as well as the arrow symbol. I'll start by adding a couple rules to my ESLintrc file to flag the lack of spaces. First off, I'm going to do keyword-spacing for the value of error. And then arrow spacing, also with the value of error. So accepting the defaults for both of those keywords, and just instructing ESLint to flag deviations from those defaults as errors. And I save that, and I've got some errors…
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)
-