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

Use commas consistently - JavaScript Tutorial

From the course: JavaScript: Best Practices for Code Formatting

Start my 1-month free trial

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…

Contents