From the course: JavaScript: Best Practices for Code Formatting
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Use a consistent format for blocks - JavaScript Tutorial
From the course: JavaScript: Best Practices for Code Formatting
Use a consistent format for blocks
- [Instructor] You've likely encountered a number of different layouts for blocks such as conditionals and functions in JavaScript code. You've probably seen code written in the One True Brace style, with the opening brace on the same line as the keyword. You may have also seen or used the Stroustrup variant, which pushes else statements onto separate lines, but keeps all other aspects of the One True Brace style. And you may have also run into the Allman style, in which starting braces get their own dedicated lines. As with all types of code formatting, each of these styles has its advantages and drawbacks. And it's important to simply pick the one that works for you and use it consistently. You can enforce this style in your code using the ESLint Brace-style rule. One other variation in writing block code is the choice of spacing before the opening brace. Including a space before a brace is a subtle, but useful best…
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
-
-