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 space after keywords and arrows

Include a space after keywords and arrows - JavaScript Tutorial

From the course: JavaScript: Best Practices for Code Formatting

Start my 1-month free trial

Include a space after keywords and arrows

- Including spaces around keywords like function and if can make your JavaScript code more readable. The same is true for spaces around arrows in arrow functions. ESLint includes a keyword spacing rule that lets your specify the format to check for keywords. ESLint also includes an arrow spacing rule that's specific to the arrows in arrow functions. My app.js file contains an arrow function, which includes if else logic. And right now, that's written without spaces before or after the if, else if, or else keywords, as well as the arrow symbol. I'll start by adding a couple rules to my ESLintrc file to flag the lack of spaces. First off, I'm going to do keyword-spacing for the value of error. And then arrow spacing, also with the value of error. So accepting the defaults for both of those keywords, and just instructing ESLint to flag deviations from those defaults as errors. And I save that, and I've got some errors…

Contents