Home  >  Article  >  Web Front-end  >  How to make single-line comments and multi-line comments in javascript

How to make single-line comments and multi-line comments in javascript

青灯夜游
青灯夜游Original
2021-09-01 16:00:346770browse

Single-line comment method: use the "//" character, the syntax is "//comment content", all characters in a line after the "//" character will be ignored and will not be parsed. Multi-line comment method: use "/*" and "*/" characters, the syntax is "/*comment information*/", any characters contained between the "/*" and "*/" symbols will be ignored and will not Analyze again.

How to make single-line comments and multi-line comments in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

A comment is a string of characters that is not parsed. JavaScript will not execute comments. We can add comments to explain JavaScript or make the code more readable.

JavaScript comments have the following two methods:

  • Single-line comments: //Single-line comment information.

  • Multi-line comments: /*Multi-line comment information*/.

1. Single-line comments in JavaScript

treats all characters in a line after the // characters as a single line Annotation information. The following comment statements can be located at different locations in the code segment to describe the functions of different areas of code.

//程序描述
function toStr(a){  //块描述
  //代码段描述
  return a.toString();  //语句描述
}

When using single-line comments, any characters or codes in the same line following // will be ignored and will not be parsed.

2. JavaScript for multi-line comments

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

/*
下面的这些代码会输出
一个标题和一个段落
并将代表主页的开始
*/
document.getElementById("myH1").innerHTML="欢迎来到我的博客";
document.getElementById("myP").innerHTML="这是一个欢迎的段落。";
/*
* jQuery JavaScript Library v3.3.1
* https://jquery.com/
* Includes Sizzle.js
* https://sizzlejs.com/
* Copyright JS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
* Date: 2019-08-21 T 17:24 Z
*/

In multi-line comments, any characters contained between the /* and */ symbols are treated as comment text and ignored.

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of How to make single-line comments and multi-line 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