JavaScript Basics Questions and Answers three basics

Source: Internet
Author: User
9. JavaScript annotations (Comments in JavaScript)
Q: How do I insert comments in JavaScript code?
A:javascript supports three different types of annotations:
Multiple-line C-style annotations. The content included in/* and/* is commented, for example:
/* This is a comment * *
/* C-style comments can span
As many lines as you are,
As shown in this example * *
A single-line comment for a C + + style. These comments begin with//, end at line ends:
This is a one-line comment
A single-line comment that is booted with an HTML comment start sequence (<!--). Note that the JavaScript interpreter ignores the end character (-->) of the HTML annotation. Consider this example:
<!--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
HTML-style annotations are not common in JavaScript code. (//boot single-line comments are simpler and easier to read). However, it is strongly recommended that you use HTML annotations to hide JavaScript code from the old version of the browser.
10. Hide the JS code from the old version of the browser (hidding JS browsers)
Q: How do I hide the JS code from the old version that supports JavaScript?
A: To prevent older browsers from displaying JS code, you can use the following methods:
Immediately after the beginning of the <script> tag, put a line of HTML-style comment opening style, no end content, so that the first two lines of your script should look like this:
<script language= "JavaScript" >
<!--
At the end of the script, put the following two lines:
-->
</script>
In this way, your HTML file will contain the following code end:
<script language= "JavaScript" >
<!--
Here to put your JS code.
Old browsers'll treat it
As an HTML comment.
-->
</script>
The old version of the browser will be the JS code as a long HTML annotation. On the other hand, JavaScript-enabled browsers normally explain the JS code between <script> and </script> (the interpreter will use the first and last lines of the JS code as Single-line comments).
is JavaScript available? (Is JavaScript enabled?)
Q: How can the user's browser not execute JavaScript code, I could give the user a warning?
A: Of course, you can display a specific warning to users who use an incompatible JavaScript browser. Put your warning message between <NOSCRIPT> and </NOSCRIPT>. This is an example:
<NOSCRIPT>
<ul>
<li>please use Netscape Navigator 3+ or Internet Explorer 3+
<li>make sure that JavaScript are enabled in your browser.
</ul>
</NOSCRIPT>
Browsers that support JavaScript ignore the content between <NOSCRIPT> and </NOSCRIPT>. Browsers that cannot execute JavaScript will display information on the page.
Note: Netscape Navigator 2 does not support <NOSCRIPT>. As a result, this message is visible to Netscape 2 users, even if they use JavaScript-enabled browsers. Keep this in mind and then rationalize the wording without misleading Netscape's 2 users. (for example, the above information assumes that your footsteps require a browser version of at least 3.) )
12. External JavaScript file (External JS files)
Q: Can I introduce the JS file from the outside, instead of all the scripts in the HTML page?
A: That's OK. You can create a file with a suffix named. js, for example, Myscipt.js. Put your JavaScript code in this file; Do not include <script> or </script> tags in the. js file.
To embed myscript.js in a Web page, you need to use these tags in an HTML file:
<script language= "JavaScript" src= "Myscript.js" >
</SCRIPT>
In fact, you'll find it handy to create a. js file to save JavaScript functions, which you can reuse in different HTML files. Note, however, that some older browsers (like Navigator 2.x and Explorer 3.x) do not load external JavaScript files.
Reserved words in JavaScript (Reserved words in JavaScript)
What are the reserved words in the q:javascript?
The reserved words in the A:javascript language are listed below. (Some of them are used in JavaScript languages and are reserved for compatibility or later possible extensions in JavaScript.) When you select 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 with
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 the 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

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.