A single-line JScript comment begins with a pair of forward slashes (//).
Here is an example of a single-line comment, followed by a line of code.
// This is a single-line comment. aGoodIdea = "Comment your code for clarity.";
A multiline JScript comment begins with a forward slash and asterisk (/*), and ends with the reverse (*/).
/* 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. */
If you attempt to embed one multiline comment within another, JScript interprets the resulting multiline comment in an unexpected way. The */ that marks the end of the embedded multiline comment is interpreted as the end of the entire multiline comment. Consequently, the text following the embedded multiline comment is interpreted as JScript code and may generate syntax errors.
In the following example, the third line of text is interpreted as JScript code because JScript has interpreted the innermost */ to be the end of the outermost comment:
/* This is the outer-most comment /* And this is the inner-most comment */ ...Unfortunately, JScript will try to treat all of this as code. */
It is recommended that you write all comments as blocks of single-line comments. This allows you to comment out large segments of code with a multiline comment later.
// 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.";
Alternatively, you can use conditional compilation to effectively comment out large segments of code.