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

Include a comma in a list of values - JavaScript Tutorial

From the course: JavaScript: Best Practices for Code Formatting

Start my 1-month free trial

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…

Contents