JavaScript Use Comments to Prevent Execution – JavaScript Tutorial


JavaScript Use Comments to Prevent Execution


Using comments to prevent 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.
example1 uses // to prevent execution of one of the code lines:

example2 uses a comment block to prevent execution of multiple lines between /* */

Example 1

//document.getElementById("myH").innerHTML = "My First Page";
document.getElementById("myP").innerHTML = "My first paragraph.";

Example 2

document.getElementById("myH2").innerHTML = "My First Page";
document.getElementById("myP2").innerHTML = "My first paragraph.";
Try It Yourself - Online Compliler >>