javascript 注释_JavaScript中的注释

news/2024/7/19 15:36:44 标签: python, java, javascript, js, mysql

javascript 注释

Like other programming languages, in JavaScript comments can be used to prevent the execution of the statements. Whenever we want to ignore the statements or any text/document from execution, we use comments.

像其他编程语言一样, JavaScript注释可用于阻止执行语句。 每当我们想要忽略语句或执行中的任何文本/文档时,我们都会使用注释。

For example: While writing the code, sometimes the logic is complex and we want to explain in our words so that we can understand the logic – we can put the explanation in the comments.

例如:在编写代码时,有时逻辑很复杂,我们想用文字解释,以便我们可以理解逻辑–可以将解释放在注释中。

There are two types of comments in JavaScript:

JavaScript有两种类型的注释

  1. Single line comment

    单行注释

  2. Multi line comments

    多行注释

JavaScript单行注释 (JavaScript single line comment)

For single line comment in JavaScript, we use double slash characters (//) before the text/code. The code/text written after the double slash (//) will be ignored by the interpreter.

对于JavaScript中的单行注释,我们在文本/代码之前使用双斜杠(//)。 解释器将忽略双斜杠(//)之后编写的代码/文本。

Syntax:

句法:

    //This text will not be executed/ interpreted

Example:

例:

<script>
	document.write("This is line1<br>");
	//document.write("This is line2<br>");
	document.write("This is line3<br>");
	//document.write("This is line4<br>");
	document.write("This is line5<br>");
</script>

Output

输出量

This is line1
This is line3
This is line5

JavaScript多行注释 (JavaScript multi line comment)

Multi-line comments can be placed between /* and */. The comment starts with /* and terminates with */. We can place any number of lines between these comment characters.

多行注释可以放在/ *和* /之间。 注释以/ *开头,以* /结束。 我们可以在这些注释字符之间放置任意数量的行。

Syntax:

句法:

    /* 
    This line will not be executed/ interpreted
    This line will also not be executed/ interpreted
    This line will also not be executed/ interpreted
    */

Example:

例:

<script>
	document.write("This is line1<br>");
	/*document.write("This is line2<br>");
	document.write("This is line3<br>");*/
	document.write("This is line4<br>");
	/*
	document.write("This is line5<br>");
	document.write("This is line6<br>");
	document.write("This is line7<br>");
	*/
	document.write("This is line8<br>");
	document.write("This is line9<br>");		
</script>

Output

输出量

This is line1
This is line4
This is line8
This is line9

在语句中注释代码 (Comment the code in a statement)

We can comment on any code in a statement by using multi-line characters.

我们可以使用多行字符对语句中的任何代码进行注释。

Example:

例:

<script>
	document.write("This is line1<br>");
	document.write("This is line2<br>");
	document.write(/*"This is line3<br>"*/"Hello world<br>");
	var result = /*a-b*/ 10-2;
	document.write("result: " + result + "<br>");
</script>

Output

输出量

This is line1
This is line2
Hello world
result: 8


翻译自: https://www.includehelp.com/code-snippets/comments-in-javascript.aspx

javascript 注释


http://www.niftyadmin.cn/n/1253913.html

相关文章

python 中的匿名函数lamda和functools模块

为什么 要把匿名函数和functools模块写在一起? 因为 lamda函数和functools模块都是对函数一种增强或者是简化。 匿名函数&#xff1a; 为了解决那些功能很简单的需求而设计一次性的需求函数 #"有名函数" def calc(n):return n**n print(calc(10))#换成匿名函数 calc…

表达式转为后缀表达式_后缀表达评估

表达式转为后缀表达式Problem statement: 问题陈述&#xff1a; Given a postfix expression, the task is to evaluate the expression and print the final value. Operators will only include the basic arithmetic operators like *, / , , and -. 给定一个后缀表达式&am…

java线程池停止线程_如何在Java中停止线程?

java线程池停止线程停止线程 (Stopping a thread) As we know that there are no direct or shortcut ways to stop thread in Java. 众所周知&#xff0c;在Java中没有直接或快捷的方式来停止线程。 As we know thread in java stops when the execution of run() method comp…

Day6(树上问题)

树的重心 定义&#xff1a;将树上某点删掉后&#xff0c;剩下的子树大小最小。 性质&#xff1a;1&#xff09;树的重心的每棵子树大小一定小于等于n/2 2&#xff09;每棵子树大小一定小于等于n/2的点一定是树的重心->最多有2个点为重心且相邻 3&#xff09;树中所有点到某点…

数据库中元组关系演算_元组关系演算| 数据库管理系统

数据库中元组关系演算table, th, td {border: 1px solid black;} table, th, td {border: 1px solid black;} Tuple Relational Calculus is a non-procedural and declarative query language. The declarative query procedure gives logical condition which is required to…

AT2673 Tree and Hamilton Pat

https://www.luogu.org/problemnew/show/AT2673 题意&#xff1a; 思路&#xff1a;与CF468D TREE类似 代码&#xff1a; #include<iostream> #include<cstdio> #include<cstring> #define ma(a,b) (a<b?b:a) #define mi(a,b) (a<b?a:b) using names…

UPSC的完整形式是什么?

UPSC&#xff1a;联盟公共服务委员会 (UPSC: Union Public Service Commission) UPA is an abbreviation of United Production of America. It is an American animation studio, better known as UPA, active from the 1940s to 1970s. UPA produced theatrical shorts for C…

c++ 字符串反转 stl_字符串分配| C ++ STL

c 字符串反转 stlIn C STL, with "string" class, we can assign, replace string by using assignment operator (), there is no more need to using strcpy() to assign the string after the declaration. 在C STL中&#xff0c;通过“ string”类 &#xff0c;…