var x = ‘Hello world’;
console.log(x);
Writing each statement on a new line, and ending it with a semi-colon, increases readability of your code, which is important when you come back to review your code in the future and also for any other programmers who might need to alter your code at some point in the future. Always aim to write code that is well structured as it makes your life a lot easier further down the road.
While on the topic of best practices, it is also a good idea to pad your statements out with white space where possible, specifically around operators. White space is ignored in JavaScript, so it’s always a good idea to make use of white space as a means of writing more readable code. Here is an example of how using white space around operators helps to increase readability:
Before