Comments can be a single line or multi line. While debugging the large piece of code, comments can be used to prevent the execution of the code.
This tutorial explains about the single line and multi line comments.
Single Line Comments
Two forward slashes ( denoted by // ) creates a single line comment. Text written after the slashes till the end of new line, will not get executed.
Single line comments can be written before the statement of after the statement.
Before the statement.
// Declare a, assign the value of 2 var a = 2; // Declare b, assign the value of a + 1 var b = a + 1;After the statement.
var a = 2; // Declare a, assign the value of 2 var b = a + 1; // Declare b, assign the value of a + 1
Multi Line Comments
Multi line comments begins with forward slash and asterick ( denoted by /* ) and ends with asterick and forward slash ( denoted by */ ). Any text written inside multi line comments will not get executed. It is also called as block comments.
/* This is a multi line comment. It will not be displayed */ document.write("Example of multi line comment");
Single line comments becomes cumbersome when more number of lines needs to be commented.