Comments in JavaScript

JavaScriptComments in JavaScript are pretty much similar to PHP.  There are 2 types of comments, single-line comment and multi-line comment.  Single-line comment is useful in case of providing small information about the code.  Multi-line comment is useful in case of providing detailed information about the code.  Single-line comment starts with 2 forward slashes (//).  Multi-line comment starts with /* and ends with */.  Example of both the comments is given below.

<html>
<head>
<title>JavaScript Tutorial </title>
</head>
<body>

<script type="text/javascript">

//This is a single line comment.
var message = "Hello World";

/*
This is a multi-line comment.
Alert function will display a message box.
*/ 
alert(message);
 
</script>
 
</body>
</html>

 

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •