JavaScript Basic Questions and Answers 3_Basic Knowledge
WBOY
Release: 2016-05-16 18:58:04
Original
966 people have browsed it
9. Comments in JavaScript Q: How do I insert comments in JavaScript code? A: JavaScript supports three different types of comments: Multiline C-style comments. Content included in /* and */ are comments, for example: /* This is a comment */ /* C-style comments can span as many lines as you like, as shown in this example */ C-style single-line comments. These comments start with // and end at the end of the line: // This is a one-line comment Use an HTML comment to start the sequence (). Consider this example: This is also a one- line JS comment because JS ignores the closing characters of HTML-style comments HTML-style comments are not common in JavaScript code. (//The single-line comment of the guide is simpler and more readable). However, it is highly recommended to use HTML comments to hide JavaScript code from older browsers. 10. Hidding JS code from old browsers (Hidding JS code from old browsers) Q: How do I hide JS code from old versions that do not support JavaScript? A: In order to prevent older browsers from displaying JS code, you can use the following method: At the beginning of the
, your HTML file will contain the following code end:
Older versions of browsers will treat JS code as a long HTML comment. On the other hand, browsers that support JavaScript will interpret the JS code between normally (the interpreter will treat the first and last lines in the JS code as single-line comments).
Q: If the user's browser cannot execute JavaScript code, can I give the user a warning? A: Of course, you can display a specific warning to users using non-JavaScript-compatible browsers. Place your warning message between
Browsers that support JavaScript will ignore the content between
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn