JavaScript comment
JavaScript Comments can be used to improve the readability of the code.
JavaScript comment
JavaScript does not execute comments.
We can add comments to explain to JavaScript, or improve readability.
Single-line comments begin with //.
This example uses a single-line comments to explain the code:
Examples
// 输出标题:
document.getElementById("myH1").innerHTML="欢迎来到我的主页";
// 输出段落:
document.getElementById("myP").innerHTML="这是我的第一个段落。";
document.getElementById("myH1").innerHTML="欢迎来到我的主页";
// 输出段落:
document.getElementById("myP").innerHTML="这是我的第一个段落。";
try it"
JavaScript multi-line comments
Multi-line comments begin with / * in * / at the end.
The following example uses a multi-line comments to explain the code:
Examples
/*
下面的这些代码会输出
一个标题和一个段落
并将代表主页的开始
*/
document.getElementById("myH1").innerHTML="欢迎来到我的主页";
document.getElementById("myP").innerHTML="这是我的第一个段落。";
下面的这些代码会输出
一个标题和一个段落
并将代表主页的开始
*/
document.getElementById("myH1").innerHTML="欢迎来到我的主页";
document.getElementById("myP").innerHTML="这是我的第一个段落。";
try it"
Use comments to prevent the execution
In the following example, a comment which used to prevent the implementation of a line of code (useful for debugging):
Examples
//document.getElementById("myH1").innerHTML="欢迎来到我的主页";
document.getElementById("myP").innerHTML="这是我的第一个段落。";
document.getElementById("myP").innerHTML="这是我的第一个段落。";
try it"
In the following example, the comment block is used to prevent the execution of code (useful for debugging):
Examples
/*
document.getElementById("myH1").innerHTML="欢迎来到我的主页";
document.getElementById("myP").innerHTML="这是我的第一个段落。";
*/
document.getElementById("myH1").innerHTML="欢迎来到我的主页";
document.getElementById("myP").innerHTML="这是我的第一个段落。";
*/
try it"
End of the line using annotations
In the following example, we put at the end of the comment line of code: