Home > Web Front-end > JS Tutorial > 【JavaScript Tutorial】JavaScript Comments

【JavaScript Tutorial】JavaScript Comments

黄舟
Release: 2016-12-24 14:37:04
Original
932 people have browsed it

JavaScript Comments

JavaScript comments can be used to improve the readability of your code.

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

This example uses single-line comments to explain the code:

Example

// 输出标题:
document.getElementById("myH1").innerHTML="欢迎来到我的主页";
// 输出段落:
document.getElementById("myP").innerHTML="这是我的第一个段落。";
Copy after login

JavaScript multi-line comments

Multi-line comments start with /* and end with */.

The following example uses multi-line comments to explain the code:

Example

/*
下面的这些代码会输出
一个标题和一个段落
并将代表主页的开始
*/
document.getElementById("myH1").innerHTML="欢迎来到我的主页";
document.getElementById("myP").innerHTML="这是我的第一个段落。";
Copy after login

Using comments to prevent execution

In the example below, the comment is used to prevent the execution of one of the lines of code (can be used for debugging):

Example

//document.getElementById("myH1").innerHTML="欢迎来到我的主页";
document.getElementById("myP").innerHTML="这是我的第一个段落。";
Copy after login

In the example below, comments are used to prevent the execution of a block of code (can be used for debugging):

Example

/*
document.getElementById("myH1").innerHTML="欢迎来到我的主页";
document.getElementById("myP").innerHTML="这是我的第一个段落。";
*/
Copy after login

Using comments at the end of lines

In the example below, we put comments at the end of the line of code Ending:

Example

var x=5;    // 声明 x 并把 5 赋值给它
var y=x+2;  // 声明 y 并把 x+2 赋值给它
Copy after login

The above is the content of JavaScript comments in [JavaScript Tutorial]. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template