var y = “Hello”;

var x = y + ‘ World!’;

As you can see, we have added spaces around the ‘=’ and ‘+’, and as a result, the code is much more readable and maintainable. This is a best practice, which you should strive towards when writing your JavaScript code.

Another best practice that developers tend to abide by is capping line lengths. Programmers tend to cut their lines off at 80 characters for increased readability. When breaking a statement, it’s usually best to break it at an operator (=, −, =, etc).

One of the final best practices we will discuss for formatting statements is around code blocks. Typically, developers will group together statements that are intended to be run together to achieve a certain action into a function that can be run at will. Let’s see an example of this in action:

After