Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-03 18:39:04 09月18日 Update

This article mainly introduces javascript how to carry out single-line comments and multi-line comments, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

The method of single-line comment: use the "/ /" character, syntax "/ / comment content", and all characters in the line after the "/ /" character will be ignored and no longer parsed. Multiline annotation method: using "/ *" and "* /" characters, syntax "/ * comment information * /", any characters contained between "/ *" and "* /" symbols will be ignored and no longer parsed.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

A comment is a string of characters that are not parsed. JavaScript does not perform comments. We can add comments to interpret the JavaScript or improve the readability of the code.

There are two ways to comment on JavaScript:

Single-line comment: / / single-line comment information.

Multiline comment: / * multiline comment information * /.

1. JavaScript makes single-line comments

Treat all characters on the line after the / / character as a single-line comment message. The following comment statements can be located in different locations of the code snippet to describe the functionality of the code in different areas.

/ / Program description function toStr (a) {/ / Block description / / Code snippet description return a.toString (); / / statement description}

When using single-line comments, any characters or code on the same line after / / are ignored and no longer parsed.

2. JavaScript makes multi-line comments

Multiline comments begin with / * and end with * /.

/ * the following code will output a title and a paragraph and will represent the beginning of the home page * / document.getElementById ("myH1") [xss_clean] = "Welcome to my blog"; document.getElementById ("myP") [xss_clean] = "this is a welcome paragraph." / * * 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 Zero /

In multiline comments, any characters contained between the / * and * / symbols are ignored as comment text.

Thank you for reading this article carefully. I hope the article "how to make single-line comments and multi-line comments in javascript" shared by the editor will be helpful to you. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Comments characters multiple lines code information articles methods different one line between paragraphs symbols statements grammar home page representatives values locations interests content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Redmi Xiaomi vpn Shulou Information