TomRed.net

  • Increase font size
  • Default font size
  • Decrease font size
Subscribe Bookmark and Share
Home Tutorials CSS JavaScript Comments

JavaScript Comments

User Rating: / 0
PoorBest 

This article outlines how to comment in JavaScript.  There are two types of comments in JavaScript single line and multi-line.

Single Line //

<script type="text/javascript">
// This is a single comment line
var test = "test"; // This is a comment after a line
</script>

By placing a double forward slash in place before text you are creating a section ignored by the JavaScript interpreter. While this is useful in the cases where you have a small amount of information to share when you want to block out a large piece of your code or where you want to add a detailed comment to a piece you require Multi-line comments.

Multiple Line /* */

In this case were are using /* to open a comment and closing with */ everything between these are ignored.

<script type="text/javascript">
/* 
This 
is 
a 
Multiline 
comment
*/

/* 
This is blocking out some code
var test2 = "test2"; 
var test3 = "test3"; 
var test4 = "test4";
*/

var test1 = "test1"; 

</script>