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.
Use commas consistently - JavaScript Tutorial
From the course: JavaScript: Best Practices for Code Formatting
Use commas consistently
- [Instructor] Several types of JavaScript statements uses commas to separate sequential items. For instance, elements in a array literals are separated by commas, as are key value pairs in object literals. When a list of values is too long for a single line, it's common to break the list up by putting each item on it's own line. This means that the commas are accompanied by line breaks. Some developers use commas at the end of each line, while others place them at the start. Whichever you choose, consistency is important. Both to make your code more readable and to enable you to catch errors, more importantly, omitted commas. In my location app, the fetch request can take a number of parameters using an object literal. The values don't all fit in a single line so I already have an error here because I've specified a maximum line length of 80 characters. So I want to break that object up, and one way to do this is to…
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)
End statements with a semicolon5m 10s
-
(Locked)
Don't rely on auto semicolon insertion4m 19s
-
(Locked)
Standardize line length6m 33s
-
(Locked)
Use commas consistently3m 38s
-
(Locked)
Include a comma in a list of values3m 21s
-
(Locked)
Challenge: Optimize punctuation31s
-
(Locked)
Solution: Optimize punctuation5m 23s
-
(Locked)
-
-