From the course: JavaScript: Best Practices for Code Formatting

Unlock the full course today

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

Use a consistent format for blocks

Use a consistent format for blocks - JavaScript Tutorial

From the course: JavaScript: Best Practices for Code Formatting

Start my 1-month free trial

Use a consistent format for blocks

- [Instructor] You've likely encountered a number of different layouts for blocks such as conditionals and functions in JavaScript code. You've probably seen code written in the One True Brace style, with the opening brace on the same line as the keyword. You may have also seen or used the Stroustrup variant, which pushes else statements onto separate lines, but keeps all other aspects of the One True Brace style. And you may have also run into the Allman style, in which starting braces get their own dedicated lines. As with all types of code formatting, each of these styles has its advantages and drawbacks. And it's important to simply pick the one that works for you and use it consistently. You can enforce this style in your code using the ESLint Brace-style rule. One other variation in writing block code is the choice of spacing before the opening brace. Including a space before a brace is a subtle, but useful best…

Contents