Home >Web Front-end >JS Tutorial >How to make document comments in javascript
Javascript document comment method: 1. Use "//" for single-line comments, just add "//" before the specified code; 2. Use "/*" and "*/" for single-line comments. For multi-line comments, just place the specified code between "/*" and "*/".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
JavaScript comments are used to explain JavaScript code and enhance its readability.
JavaScript comments can also be used to prevent execution when testing alternative code.
Single-line comments
Single-line comments start with //.
Any text between // and the end of the line will be ignored by JavaScript (will not be executed).
This example uses a single-line comment before each line of code:
<!DOCTYPE html> <html> <body> <h1 id="myH"></h1> <p id="myP"></p> <script> // 改变标题: document.getElementById("myH").innerHTML = "JavaScript 注释"; // 改变段落: document.getElementById("myP").innerHTML = "我的第一个段落。"; </script> </body> </html>
Effect:
Multi-line comments
Multi-line comments start with /* and end with */.
Any text between /* and */ will be ignored by JavaScript.
This example uses multi-line comments (comment blocks) to explain the code:
<!DOCTYPE html> <html> <body> <h1 id="myH"></h1> <p id="myP"></p> <script> /* 下面的代码会改变 id = "myH" 的标题 以及 id = "myp" 的段落 */ document.getElementById("myH").innerHTML = "JavaScript 注释"; document.getElementById("myP").innerHTML = "我的第一个段落。"; </script> </body> </html>
Effect:
[Recommended learning: javascript Advanced Tutorial】
The above is the detailed content of How to make document comments in javascript. For more information, please follow other related articles on the PHP Chinese website!