Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Using Comments to Prevent Execution

Using comments to prevent code execution is useful for testing purposes.

By adding // at the beginning of a code line, that line is converted from executable code to a comment.

The following example demonstrates how to use // to disable one of the code lines:

Example

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

This example employs a comment block to disable the execution of multiple lines:

Example

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