JavaScript comments can be used to describe JavaScript code and to make it more simple and used to stop the execution when testing alternative principles.

  • Single line comments //.
  • Multi-line comments /* and end with */.
Single line comments  //.
var x = 5;      // Declare x, give it the value of 5
var y = x + 2;  // Declare y, give it the value of x + 2
Multi-line comments 
/* 
you can describe what you are making in the program will not be executed
 */



/*

you can describe what you are making in the program will not be executed

here to testing alternative principles.

 */

Example:

<!DOCTYPE html>
<html>
    <body>

        <h1 id="my-heading"></h1>
        <p id="my-p"></p>

        <script>
            /*
             The code below will change
             the heading with id = "my-heading"
             and the paragraph with id = "my-p"
             */
            document.getElementById("my-heading").innerHTML = "Javascript tutorial";
            document.getElementById("my-p").innerHTML = "My first javascript program.";
            
            //innerHTML = means insert content inside selected html elements
        </script>

    </body>
</html>


output: