How to add comment in JavaScript

A comment is a part of the program which doesn’t execute when running the program.

Its only purpose is to be read by someone who is editing the code.

In JavaScript, there are two types of comments –

  • Single line, and
  • Multiple lines

How to add comment in JavaScript


Contents

  1. Single Line
  2. Multiple Lines
  3. Useful for

 

1. Single Line

Use // for single line comments. If you want to comment more than one line using this then you need to put this on each line.

Example

<script type="text/javascript"> 

// This is a single line comment 

</script>

 

2. Multiple Lines

It starts with /* and ends with */. Between this the content that needs to be the comment.

Example

<script type="text/javascript"> 

/* 
This is a multi-line comment block 
*/

</script>

 

3. Useful for

  • To let others understand what you are doing – Comments let other programmers understand what you were doing in each step ( if you work in a group ).
  • To remind yourself what you did.

Related Post

Spread the love

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *