In JavaScript comments can be used to explain JavaScript code, and to make it more readable.These javascript comments can also be used to prevent execution, when testing alternative code.
Description
JavaScript supports three different types of comments:
- Multiple-line C-style comments. Everything between /* and */ is a comment
- Single-line comments of C++ style. These comments begin with // and continue up to the next line break:
- One-line comments with the HTML comment-opening sequence (< --). Note that the JavaScript interpreter ignores the closing characters of HTML comments (-->).
For example:
/* This is a comment */
/* C-style comments can span
as many lines as you like,
as shown in this example */
/* This is a comment */
/* C-style comments can span
as many lines as you like,
as shown in this example */
// This is a one-line comment
<! -- This is treated as a one-line JS comment
<! -- It works just like a comment beginning with //
<! -- -->This is also a one-line JS comment
<! -- --> because JS ignores the closing characters
<! -- --> of HTML-style comments
<! -- It works just like a comment beginning with //
<! -- -->This is also a one-line JS comment
<! -- --> because JS ignores the closing characters
<! -- --> of HTML-style comments
HTML-style comments are not usually found in the middle of JavaScript code.(The // comments are simpler and easier to read.)
No comments:
Post a Comment