Home >Web Front-end >JS Tutorial >How to make document comments in javascript

How to make document comments in javascript

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-06-15 16:00:354290browse

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 "*/".

How to make document comments in javascript

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:

How to make document comments in javascript

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:

How to make document comments in javascript

[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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn