WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript Comments


JavaScript remarks can be utilized to clarify JavaScript code, and to make it more readable.

JavaScript remarks can likewise be utilized to avert execution, when testing elective code.


Single Line Comments

Single line remarks begin with/.

Any message between/and the stopping point, will be overlooked by JavaScript (won't be executed).

This model uses a solitary line remark before each line, to clarify the code:

Example

/Change heading:
document.getElementById("myH").innerHTML = "My First Page";
/Change paragraph:
document.getElementById("myP").innerHTML = "My first paragraph.";
Try it yourself »

This model uses a solitary line remark toward the finish of each line, to clarify the code:

Example

var x = 5;     /Declare x, give it the estimation of 5
var y = x + 2; /Declare y, give it the estimation of x + 2
Try it yourself »

Multi-line Comments

Multi-line remarks begin with/* and end with */.

Any message between/* and */will be disregarded by JavaScript.

This model uses a multi-line remark (a remark hinder) to clarify the code:

Example

/*
The code underneath will change
the heading with id = "myH"
what's more, the section with id = "myP"
in my web page:
*/
document.getElementById("myH").innerHTML = "My First Page";
document.getElementById("myP").innerHTML = "My first paragraph.";
Try it yourself »

Using Comments to Prevent Execution

Using remarks to anticipate execution of code, is reasonable for code testing.

Adding/before a code line changes the code lines from an executable line to a comment.

This model uses/to forestall execution of one of the code lines:

Example

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

This model uses a remark square to forestall execution of different lines:

Example

/*
document.getElementById("myH").innerHTML = "My First Page";
document.getElementById("myP").innerHTML = "My first paragraph.";
*/
Try it yourself »