Loading

Comments in JS

  • In JavaScript, Comments are used to give information about the code, so that users can easily understand the code.
  • Comments are ignored by the JavaScript interpreter and are meant for human readers, including developers and collaborators, to understand the code.

There are two types of comments in JS:

  • Single line comment
  • Multiline comment

Single-line comment:

  • Single-line comments are used to add comments to a single line of code
  • They are represented as  '//'

Example:

<script>  
// It is single line comment  
document.write("Welcome to Quipoin");  
</script>  
<html>

<body>
   <script>
      var a = 10;
      var b = 10;
      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:

20


Multiline comment:

  • Multiline comments are used to add both single-line and multiline comments.
  • It is represented as starting with /* and ending with */.

Example:

/* your code here  */  
<html>

<body>
   <script>
      /* It is multi line comment.  
      It will not be displayed */
      document.write("Welcome to Quipoin");  
   </script>
</body>

</html>

Output:

Welcome to Quipoin