Comments

Comments

Comments are useful explanations you can write about your code. Comments will help you memorize what logic you used when you go back to your code after some time. This will also help others understand your code better. Comments get ignored when the code is being run.

Single Line Comments

Single line comments begin with double slashes (//), everything after the slashes until end of line is ignored.

You can add single line comments to write small explanations or stop a line of code from executing.

//this is a single line comment
var monthname = "January";
document.write(monthname); //One more comment
document.write("<br>"); 

//monthname = "February"; //another comment
//document.write(monthname);
//document.write("<br>"); 

monthname = "March";
document.write(monthname);
The above code will display the following output:
January
March

Multi-Line Comments

Multi line comments begin with /* and end with */. Everything that comes in between is ignored.

With Multi line comments you can write explanations that span large number of lines. You can also stop larger sections of code from executing.

/* Writing Comments that 
span 
multiple 
lines of code.
*/
var monthname = "January"; /* Setting to January month name */
document.write(monthname); 
document.write("<br>"); 

/*monthname = "February"; 
document.write(monthname);
document.write("<br>"); 

monthname = "March"; 
document.write(monthname);
document.write("<br>"); 
*/
monthname = "April"; 
document.write(monthname);
The above code will display the following output:
January
April