Single-Line Comments

By: Dusty Arlia
Published on March 5, 2013
Last Updated on Wednesday, July 15, 2015 at 1:33 PM
Total Updates: 3

When including comments in your code, you will most often use single-line comments. Single-line comments start off with two forward slashes (//). These two forward slashes indicate to the JavaScript interpreter that everything following the two slashes up until the next line break should be ignored. Here is an example of what they look like:

//this is a single-line comment
var i = 1;   //and this is a single-line comment

//This comment is spanning
//more than a single line,
//three lines to be exact.

There are a couple reasons why you will be using these comments more frequently than multiline comments. First, you can use single-line comments across multiple lines like demonstrated above. And secondly, single-line comments are more difficult to confuse with regular lines of code. The disadvantage of multiline comments is that if the comment is too long, you will have to take an extra second to find the starting and ending comment delimiters - (/**/. With single-line comments, this is not a problem. Just look to the left of the comment to find the double forward slashes (//).