Home  >  Article  >  Web Front-end  >  How to use comments in javascript

How to use comments in javascript

coldplay.xixi
coldplay.xixiOriginal
2021-04-09 14:48:137726browse

How to use comments in JavaScript: 1. Single-line comments begin with [//], and any text between [//] and the end of the line will be ignored by JavaScript; 2. Multi-line comments begin with [*/ ] starts with [*/] and ends with [*/].

How to use comments in javascript

The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.

How to use comments in javascript:

1. Single-line comments

Single-line comments start with // starts.

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:

Example

// 改变标题:
 document.getElementById("myH").innerHTML = "我的第一张页面";
// 改变段落:
 document.getElementById("myP").innerHTML = "我的第一个段落。";

2. Multi-line comments

many 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:

Example

/*
 下面的代码会改变
 网页中
 id = "myH" 的标题
 以及 id = "myP" 的段落:
*/
document.getElementById("myH").innerHTML = "我的第一张页面";
document.getElementById("myP").innerHTML = "我的第一个段落。";

Related free learning recommendations: javascript video tutorial

The above is the detailed content of How to use 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