Home >Web Front-end >JS Tutorial >What are javascript annotations?
Javascrip comment characters are divided into single-line comment characters "//" and multi-line comment characters "/**/". Single-line comments start with "//", followed by the comment content, and the syntax is "//comment content"; multi-line comments start with "/*" and end with "*/" ending with the comment content in the middle. The syntax is "/* comment content*/" .
JavaScript Comments
JavaScript will not execute comments.
We can add comments to explain JavaScript or improve the readability of the code.
Single-line comments start with //.
Example
The following example uses a single-line comment to explain the code:
<!DOCTYPE html> <html> <body> <h1>Welcome to my Homepage</h1> <p>This is my first paragraph.</p> <script> // 输出标题: document.getElementById("myH1").innerHTML="Welcome to my Homepage"; // 输出段落: document.getElementById("myP").innerHTML="This is my first paragraph."; </script> <p><b>注释:</b>注释不会被执行。</p> </body> </html>
JavaScript Multi-line Comment
Multi-line comments start with /* and end with */.
The following example uses multi-line comments to explain the code:
Example
<!DOCTYPE html> <html> <body> <h1>Welcome to my Homepage</h1> <p>This is my first paragraph.</p> <script> /* 下面的这些代码会输出 一个标题和一个段落 并将代表主页的开始 */ document.getElementById("myH1").innerHTML="Welcome to my Homepage"; document.getElementById("myP").innerHTML="This is my first paragraph."; </script> <p><b>注释:</b>注释块不会被执行。</p> </body> </html>
The above is the detailed content of What are javascript annotations?. For more information, please follow other related articles on the PHP Chinese website!