다음을 통해 공유


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 코드로 해석됩니다.

/* 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.";

또는 조건부 컴파일을 사용하여 큰 세그먼트의 코드를 효율적으로 주석으로 처리할 수 있습니다.

참고 항목

기타 리소스

JScript 참조

JScript 언어 둘러보기

조건부 컴파일