JScript 8.0
JScript 注释

单行 JScript 注释以两个正斜杠 (//) 开始。

代码中的注释

以下是单行注释(后跟一行代码)的一个示例。

// This is a single-line comment.
aGoodIdea = "Comment your code for clarity.";

多行 JScript 注释以正斜杠和星号 (/*) 开头,以相反的顺序 (*/) 结束。

/*
This is a multiline comment that explains the preceding code statement.
The statement assigns a value to the aGoodIdea variable. The value, 
which is contained between the quote marks, is called a literal. A 
literal explicitly and directly contains information; it does not 
refer to the information indirectly. The quote marks are not part 
of the literal.
*/

如果试图在一个多行注释中嵌入另一个多行注释,JScript 将以一种意想不到的方式解释生成的多行注释。标记嵌入的多行注释结尾的 */ 将被解释为整个多行注释的结尾。因此,在嵌入的多行注释后面的文本将被解释为 JScript 代码,并可能生成语法错误。

在下面的示例中,由于 JScript 将最里面的 */ 解释为最外面注释的结尾,因此第三行文本将被解释为 JScript 代码:

/* This is the outer-most comment
/* And this is the inner-most comment */
...Unfortunately, JScript will try to treat all of this as code. */

建议将所有注释编写为单行注释的块。这样就允许随后用一个多行注释来注释大段代码。

// This is another multiline comment, written as a series of single-line comments.
// After the statement is executed, you can refer to the content of the aGoodIdea
// variable by using its name, as in the next statement, in which a string literal is
// appended to the aGoodIdea variable by concatenation to create a new variable.
var extendedIdea = aGoodIdea + " You never know when you'll have to figure out what it does.";

或者还可以使用条件编译安全有效地注释大段代码。

请参见