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 comma in a list of values - JavaScript Tutorial
From the course: JavaScript: Best Practices for Code Formatting
Include a comma in a list of values
- [Instructor] Lists of values like array elements, key value pairs and object literals, and function arguments require comma's to separate values. No comma is required at the end, but when you're using a multiline format for a series of values, and you're using a terminal comma format rather than putting commas at the beginning of the line, then it's a best practice to include a comma after the last item as well. There are a couple of solid reasons for this. First, it makes it harder to omit a comma between items when you add it to your list, because the comma that used to be at the end, automatically becomes the separator before the new item. The terminal comma also makes diff's cleaner, as you don't see a separate deletion and insertion for the added comma. Instead, the only change is the newly inserted line. In the fetch code in my app.js file for my local events app, I'm specifying an object containing a couple of…
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)
-
-