Basic JavaScript Q & A 3

Source: Internet
Author: User
Tags html comment

9. Comments in JavaScript)
Q: How do I insert comments in JavaScript code?
A: JavaScript supports three different types of Annotations:
Comments of the multi-line C style. The content included in/* and */is annotated, for example:
/* This is a comment */
/* C-style comments can span
As your lines as you like,
As shown in this example */
Single line comment of the C ++ style. These comments start with // and end with the end of the line:
// This is a one-line comment
Start the sequence with HTML annotation (<! --) The comment of the bootstrap line. Note that the JavaScript interpreter ignores the ending character (-->) of the HTML comment ). Consider this instance:
<! -- This is treated as a one-line JS comment
<! -- It works just like a comment beginning //
<! --> This is also a one-line JS comment
<! --> Because JS ignores the closing characters
<! --> Of HTML-style comments
HTML style annotations are not common in JavaScript code. (// Single-line comments guided are simpler and easier to read ). However, we strongly recommend that you use HTML annotations to hide JavaScript code from an earlier browser.
10. Hide the JS code from the old browser (Hidding JS code from old browsers)
Q: How can I hide JS Code from an old version that does not support JavaScript?
A: To prevent older browsers from displaying JS code, you can use the following methods:
After the <script> label at the beginning, immediately put a line of the HTML style comment at the beginning of the style, there is no end content, so the first two lines of your script should look like:
<Script language = "JavaScript">
<! --
Put the following two lines at the end of the script:
// -->
</Script>
In this way, your HTML file will contain the following code:
<Script language = "JavaScript">
<! --
Here you put your JS code.
Old browsers will treat it
As an HTML comment.
// -->
</Script>
The old browser will regard JS Code as a long HTML comment. On the other hand, browsers that support JavaScript will normally interpret the JS Code between <script> and </script> (the interpreter will treat the first line and the last line in the JS Code as a single line comment ).
11. Is JavaScript available? (Is JavaScript enabled ?)
Q: How can I give a warning if my browser cannot execute JavaScript code?
A: Of course, you can give users who use incompatible JavaScript browsers A specific warning. Place your warning information between <NOSCRIPT> and </NOSCRIPT>. This is an example:
<NOSCRIPT>
<H3> This page uses JavaScript </H3>
<Ul>
<Li> Please use Netscape Navigator 3 + or Internet Explorer 3 +
<Li> Make sure that JavaScript is enabled in your browser.
</Ul>
</NOSCRIPT>
Browsers that support JavaScript ignore content between <NOSCRIPT> and </NOSCRIPT>. Browsers that cannot execute JavaScript will display information on the page.
Note: Netscape Navigator 2 does not support <NOSCRIPT>. Therefore, this message is visible to users who use the browser Netscape 2 that supports JavaScript. Remember this, and then use the appropriate wording to avoid misleading users of Netscape 2. (For example, the above information assumes that the browser version must be at least 3 in your step .)
12. External JavaScript Files (External JS Files)
Q: Can I introduce JS files from outside, instead of storing all scripts on the HTML page?
A: Yes. You can create a file with the suffix ". js", for example, myscipt. js. Put your JavaScript code in this file; do not include the <script> or </script> tag in the. js file.
To embed myscript. js into a webpage, you need to use these tags in the HTML file:
<Script language = "JavaScript" SRC = "myscript. js">
</SCRIPT>
In fact, you will find it very convenient to create. js files and save JavaScript Functions. You can reuse these functions in different HTML files. However, note that some earlier browsers (such as Navigator 2.x and Explorer 3.x) do not load external JavaScript files.
13. Reserved words in JavaScript)
Q: What are reserved words in JavaScript?
A: Reserved Words in JavaScript are listed below. (Some of them are used in JavaScript, while JavaScript is reserved for compatibility or future extensions .) When selecting JavaScript variable names, avoid these reserved words!
Abstract else instanceof switch
Boolean enum int synchronized
Break export interface this
Byte extends long throw
Case false native throws
Catch final new transient
Char finally null true
Class float package try
Const for private typeof
Continue function protected var
Debugger goto public void
Default if return volatile
Delete implements short while
Do import static
Double in super
In addition to the above reserved words, it is best to avoid the following identifiers as JavaScript variable names. These are the names of client objects, methods, or properties in Netscape Navigator or Internet Explorer.
Alert hidden outerWidth
All history packages
Anchor image pageXOffset
Anchors images pageYOffset
Area isNaN parent
Array java parseFloat
Assign JavaArray parseInt
Blur JavaClass password
Button JavaObject pkcs11
Checkbox JavaPackage plugin
ClearTimeout innerHeight prompt
ClientInformation innerWidth prototype
Close layer radio
Closed layers reset
Confirm length screenX
Crypto link screenY
Date location scroll
DefaultStatus Math secure
Document mimeTypes select
Element name self
Elements navigate setTimeout
Embed navigator status
Embeds netscape String
Escape Number submit
Eval Object sun
Event offscreenBuffering taint
FileUpload onblur text
Focus onerror textarea
Form onfocus top
Forms onload toString
Frame onunload unescape
Frames open untaint
FrameRate opener valueOf
Function option window
GetClass outerHeight

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.