var y = “Hello”; // Declare a variable with the string ‘Hello’

var x = y + ‘ World!’; // Join the variable y with the string World!’

console.log(x); // Log the variable x to the console

As you can see, this is a much cleaner and clearer way to document your code – just try to make sure the entire line (statement and comment) are below the 80-character best practice for line lengths.

Block comments

Sometimes it’s not beneficial to comment on each individual line of a function if the statement itself is fairly self-explanatory. In this situation it is often better to write a comment about the entire function instead. In these cases, we can make use of block comments. Block comments are started with /* and ended with */. Any text between the two tags is declared as a comment and can span over multiple lines. Let’s see an example of how we can make use of block comments in our code: