Comments in JavaScript

 
Mostly Comments are used to explain the JavaScript code so that end user can understand your code and easy to readable.
There are two types of comment we can use in java script

1. Single line comments.
2. Multi Line comment.

Single Line Comment

Single line comments start with // and use to comment one line at a time
Example

<script type="text/javascript">
    // This is comment line
    document.write("<h2>Header Line</h2>");
    // Following are two paragraphs:
    document.write("<p> paragraph1.</p>");
    document.write("<p> paragraph2.</p>");
</script>

Multi Line Comment

Multi Line comment start with /* and end with */ and use to comment a block of code or more than one line at a time.
Example

<script type="text/javascript">
     /*
     Comment more than one line
     At a single time
    */
    document.write("<h2>Header Line</h2>");
    document.write("<p> paragraph1.</p>");
    document.write("<p> paragraph2.</p>");
</script>

We can also comment code line to prevent execution as follows

Single line

<script type="text/javascript">
    // document.write("<h2>Header Line</h2>");
    document.write("<p> paragraph1.</p>");
    document.write("<p> paragraph2.</p>");
</script>

Multi Line

<script type="text/javascript">
    /* document.write("<h2>Header Line</h2>");
    document.write("<p> paragraph1.</p>");
    document.write("<p> paragraph2.</p>"); */
</script>

We can also use comments after code line

<script type="text/javascript">
    document.write("<h2>Header Line</h2>"); // this is Header line
    document.write("<p> paragraph1.</p>");
    document.write("<p> paragraph2.</p>");
</script>