JavaScript: Best Practices for Code Formatting

JavaScript: Best Practices for Code Formatting

1h 51mIntermediate2019-09-10

Authors

Sasha Vodnik

Sasha Vodnik

Principal Technical Course Developer at DocuSign

Course details

JavaScript offers developers tremendous power, but also a wide variety of code style choices. Its evolution over decades and shifts in audience and approach have left communities fragmented and impeded code sharing. In this course, longtime coder and teacher Sasha Vodnik provides a core set of practices for creating code that can be read by more people than its creators. Learn about formatting details like commenting, punctuation, and spacing to maximize your code's ability to travel and thrive.

Learning objectives
Using modern deployment tools
Working with ESLint
Creating easy-to-read comments
Using commas consistently
Standardizing line length in your code
Using a consistent format for blocks
Choosing and implementing a standard indent

Skills covered

JavaScriptOracleLearningProgramming LanguagesSoftware Development

Concepts

Introduction

  • Modern standards for your JavaScript
  • What you should know
  • Set up your environment

Why Best Practices

  • Style guides
  • Use modern deployment tools
  • ESLint
  • Foundational practice - Use strict mode

Creating Comments

  • Use single-line syntax for single lines
  • Multi-line syntax with leading asterisks
  • Include leading spaces in comments
  • Challenge - Create JavaScript comments
  • Solution - Create JavaScript comments

Using Punctuation

  • End statements with a semicolon
  • Don't rely on auto semicolon insertion
  • Standardize line length
  • Use commas consistently
  • Include a comma in a list of values
  • Challenge - Optimize punctuation
  • Solution - Optimize punctuation

Using Spacing

  • Indent consistently
  • Space before and after operators
  • Use a consistent format for blocks
  • Include a space after keywords and arrows
  • Use consistent spacing before function signature parentheses
  • Break up and indent long-method chains
  • Space consistently within enclosing characters
  • Space after commas, but not before
  • Limit blank space to one line
  • Challenge - Optimize spacing
  • Solution - Optimize spacing

Conclusion

  • Next steps
40,000 Toman