/    /  Javascript-Comments

Javascript-Comments

 

JavaScript Comments is used to add information about the code, warnings, or suggestions so that end-user can easily understand the code.

It is ignored by the JavaScript engine i.e. embedded in all browsers.

 

Two types of comments in JavaScript.

 

  1. Single-line Comment
  2. Multi-line Comment

 

Single-line Comment:

 

Represented by double forward slashes (//) and it can be used before and after the statement.

 

Example:

 

<html>
<body>
<script> 
var a=10; 
var b=60; 
var c=a+b;//It adds values of a and b variable 
document.write(c);//prints sum of 10 and 20 
</script>  
</body>
</html>

 

OUTPUT:

 

70

 

Multi line Comment:

 

Represented by forwarding slash with an asterisk then asterisk with forwarding slash.

 

Example:

 

<html>
<body>
<script> 
/* It is multi line comment. 
It will not be displayed */ 
document.write("example of javascript multiline comment"); 
</script> 
</body>
</html>

 

OUTPUT:

 

Javascript-Comments