Using Comments to Prevent Action

Using comments to prevent action, or execution of code, is suitable for code testing. Adding // in front of a code line changes the code lines from an executable line to a comment. This example uses // to prevent execution of one of the code lines:

HTML file: Displayed by browser:
<body>
<h1 id="myH"></h1>
<p id="myP"></p>
<script>
   //document.getElementById("myH").innerHTML = "My First Page";
   document.getElementById("myP").innerHTML = "My first paragraph.";
</script>
<p><strong>Note:</strong> The comment block is not executed.</p>
</body>

Note: The comment block is not executed.

The following example uses a comment block to prevent execution of multiple lines:

HTML file: Displayed by browser:
<body>
<h1 id="myH"></h1>
<p id="myP"></p>
<script>
   /*
   document.getElementById("myH").innerHTML = "Welcome to my Homepage";
   document.getElementById("myP").innerHTML = "This is my first paragraph.";
   */

</script>
<p><strong>Note:</strong> The comment block is not executed.</p>
</body>

Note: The comment block is not executed.


BackTable of ContentsNext