JavaScript Statements: Comments

Not all JavaScript statements are "executed". Code after double slashes // or between /* and */ is treated as a comment. Comments are ignored by browsers, and will not be executed:

HTML file: Displayed by browser:
<h2>Comments are NOT Executed</h2>

<p id="demo"></p>

<script>
    var x = 5; // I will be executed
     // var x = 6; I will not be executed
    document.getElementById("demo").innerHTML = x;
</script>

Comments are NOT Executed

Comments for a single line are preceded by a double-slash (//), while comments that span multiple lines are preceded by a /* and followed by a */.

       // This is a single-line comment.

       /* This is a multiple-line comment.
         It can be of any length, and
         you can put whatever you want here. */

Back Table of Contents Next