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.
Space consistently within enclosing characters - JavaScript Tutorial
From the course: JavaScript: Best Practices for Code Formatting
Space consistently within enclosing characters
- [Instructor] There's a wide variety of approaches to spacing after an opening paren bracket or brace, and before the corresponding closing character. Developers who pad some or all of these enclosing characters with spaces may feel that the spaces make the enclosed values easier to read. On the other hand, the choice to omit the spaces has the advantage of creating a clear association between values and the enclosing characters which generally indicate what type of data is enclosed. Many style guides specify an approach to spacing within enclosing characters. So if your project or organization has a style guide, that's a great place to start. If you're creating your own style, then you should pick a style for each type of character and use that style consistently. Note that the style doesn't need to be the same among all types of enclosing characters. In fact, popular style guides often set out one or more distinct styles…
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
-
-