Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the comment characters in javascript

Shulou Source: shulou.com Published: 2022-06-03 07:21:18 09月15日 Update

This article mainly shows you "what are the comments in javascript", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what are the notes in javascript" this article.

There are two kinds of comments in javascript: 1, the single-line comment character "/ /", which is only valid on the line, and all the content after "/ /" will be regarded as the content of the comment; 2, the multi-line comment character "/ * /", all the content that appears between "/ *" and "* /" will be regarded as the content of the comment.

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

In javascript, comment code is divided into multi-line comments and single-line comments

Single-line comments: use "/ /" for single-line comments; all content after "/ /" will be regarded as the content of the comment and will not affect the content before "/ /".

Multiline comments: use "/ * /" for multiline comments; everything that appears between "/ *" and "* /" is treated as the content of the comment.

The basic structure is as follows:

Single-line comment

/ / I am the commented out text, here can also be the js code

Multiline comments:

/ * I am the commented out text and I pretend to be the commented out js code * /

The method of single-line comments in js

In js code, use the "/ /" symbol to comment out a single line of code or add a description of the code.

Example 1: comment out a single line of code

Js Code:

/ / [xss_clean] (''); [xss_clean] ('https://www.php.cn/');

Example 2: add a description to each line of code

Js Code:

Var a = 1; / / declare a variable await variables; / / add 1 [xss_clean] (a) to the variable; / / output this variable

The method of multiline comments in js

In js code, use / * and * / symbols to comment out multiple lines of code.

Example 1: comment out multiple lines of js code

Js Code:

The code here is commented out of var a = 1 position bank *; [xss_clean] (a); * / a = a + 5 position console.log (a)

Add multiple lines of code description to the example 2:js code

Js Code:

/ * here is an illustration of the following code. I'm just giving a simple example * / var a = 1x a = a + 5x console.log (a)

Supplementary note:

In some dedicated code editors, such as "VScode", "Notepad++", etc., the colors of normally executed code and commented-out code are different and can be easily distinguished.

Take the 'vscode' editor as an example, as shown in the following figure

Description:

1. The font of the commented out code or description is green

2. The normal code is white or other colors

3. Due to editor or personal settings, the code color in the code editor will be different.

The above is all the content of the article "what are the comment symbols in javascript"? thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Comments code content multilines editors variables articles colors differences between text methods symbols learning help valid personal examples reasons just Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Huawei MySQL Shulou Tech Info vpn