From the course: JavaScript: Best Practices for Code Formatting

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Space after commas, but not before

Space after commas, but not before - JavaScript Tutorial

From the course: JavaScript: Best Practices for Code Formatting

Start my 1-month free trial

Space after commas, but not before

- [Instructor] Commas separate values in JavaScript in a number of situations. It's common to write commas in code the same way you would use them in a sentence, with no space before and a space after. However, other comma styles are used as well, including a space before but no space after or no spaces on either side. I use a space only after commas, and so far, I've been writing my ESLintRC file using that format. I want to add a rule to flag errors if my spacing deviates. ESLint supports the comma spacing rule, which lets me specify which style I want to use and how I want it flagged. So over in my ESLintRC file I'm going to add a new line, and that's going to be comma-spacing and in an array, I going to specify that I want it to be flagged as an error, and then I need an object literal. I'm going to specify the value before with a value of false, and a value of after, and give that a value of true. Got to make sure…

Contents