JAVASCRIPT

All Languages C CPP JAVA HTML CSS JAVASCRIPT PYTHON

JavaScript Comments

The JavaScript comments are meaningful way to deliver message. It is used to add information about the code, warnings or suggestions so that end user can easily interpret the code.
The JavaScript comment is ignored by the JavaScript engine i.e. embedded in the browser.

Advantages of JavaScript comments

There are mainly two advantages of JavaScript comments.

Types of JavaScript Comments

There are two types of comments in JavaScript.

  1. Single-line Comment
  2. Multi-line Comment
<html>
<body>
<script>  
// It is single line comment  
document.write("hello javascript");  
</script>
  </body>
</html>

hello javascript

JavaScript Multi line Comment

It can be used to add single as well as multi line comments. So, it is more convenient.

It is represented by forward slash with asterisk then asterisk with forward slash. For example:

/* your code here */

It can be used before, after and middle of the statement.

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