JavaScript Best Practices

We've covered several introductory concepts for JavaScript programming in this course and how to debug your code. We'll review some coding guidelines and best practices you'll use as a JavaScript developer to ensure consistency, readability, security, and accessibility. Read this article to learn about some of the best practices for developing programs.

Control statements

Write control statements like this:

if(iceCream) {
  alert('Woo hoo!');
}

Not this:

if (iceCream){
  alert('Woo hoo!');
}

Also bear in mind:

  • There should be no space between a control statement keyword and its opening parenthesis.
  • There should be a space between the parentheses and the opening curly brace.