Question: What is JavaScript?
Answer: JavaScript is a scripting language designed for adding interactivity to Web pages. The language was first implemented by Netscape Communications in Netscape Navigator 2 beta (1995). JavaScript is different from the Java language (developed at Sun Microsystems). However, the two languages can interoperate well.
Client-side JavaScript programs, or scripts, are usually embedded directly in HTML source of Web pages. (Note: There is also server-side JavaScript, but it's beyond the scope of this FAQ collection.) Depending on the Web developer's intent, script code may run when the user opens the Web page, clicks or drags some page element with the mouse, types something on the keyboard, submits a form, or leaves the page.
In most existing implementations, JavaScript is an interpreted language. This means that scripts execute without preliminary compilation, i.e. without conversion of the script text into system-dependent machine code. The user's browser interprets the script, that is, analyzes and immediately executes it. JavaScript is supported by the following browsers:
* Netscape Navigator (beginning with version 2.0)
* Microsoft Internet Explorer (beginning with version 3.0)
* Firefox
* Safari
* Opera
* Google Chrome
* Any other browser whose vendor licensed or implemented JavaScript.
Thus, most Internet users today have browsers that support JavaScript. That's why JavaScript is one of the most popular tools in the Web developer's arsenal.
Question: Where can I get JavaScript documentation?
Answer: Online JavaScript documentation is available at these sites:
* http://www.mozilla.org/js/language/ - Mozilla.org JavaScript Resources page
* http://msdn.microsoft.com/en-us/library/72bd815a.aspx - JScript at Development Tools and Languages section of MSDN Library.
* http://msdn.microsoft.com/en-us/library/hbxc2t98.aspx - JScript at Web Development and Scripting section of MSDN Library.
In addition, you can find JavaScript discussions, online tutorials, links, code examples, and hundreds of useful scripts at the following sites (of course this list is incomplete and serves only as a starting point):
* http://www.WebReference.com/programming/JavaScript/ - tutorials and in-depth discussions
* http://www.irt.org - FAQ collections in several categories, including JavaScript
* http://www.JavaScripts.com - lots of scripts and code examples
* http://www.JavaScripter.net/faq/ - this FAQ collection.
Question: How do I insert comments in JavaScript code?
Answer: JavaScript supports three different types of comments:
1. Multiple-line C-style comments. Everything between /* and */ is a comment, for example:
/* This is a comment */
/* C-style comments can span
as many lines as you like,
as shown in this example */
2. One-line comments of C++ style. These comments begin with // and continue up to the next line break:
// This is a one-line comment
3. One-line comments with the HTML comment-opening 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 usually found in the middle of JavaScript code. (The // comments are simpler and easier to read.) However, it is strongly recommended to use HTML comment
Question: How do I hide JS code from old browsers that do not support JavaScript?
Answer: To prevent old browsers from displaying your JS code, do the following:
1. Immediately after the opening
Thus, your HTML file will contain the following fragment:
Old browsers will treat your JS code as one long HTML comment. On the other hand, new JavaScript-aware browsers will normally interpret JS code between the tags (the first and last lines of your JS code will be treated by the JavaScript interpreter as one-line comments).
Question: If the user's browser cannot execute JavaScript code, can I display a warning for the user?
Answer: Yes, you can display a special warning for users of JavaScript-incapable browsers. Put your warning text between the tags . Here's an example:
JavaScript-enabled browsers will ignore everything between . Browsers that cannot execute JavaScript will display your message on the page. NOTE: The
Answer: JavaScript is a scripting language designed for adding interactivity to Web pages. The language was first implemented by Netscape Communications in Netscape Navigator 2 beta (1995). JavaScript is different from the Java language (developed at Sun Microsystems). However, the two languages can interoperate well.
Client-side JavaScript programs, or scripts, are usually embedded directly in HTML source of Web pages. (Note: There is also server-side JavaScript, but it's beyond the scope of this FAQ collection.) Depending on the Web developer's intent, script code may run when the user opens the Web page, clicks or drags some page element with the mouse, types something on the keyboard, submits a form, or leaves the page.
In most existing implementations, JavaScript is an interpreted language. This means that scripts execute without preliminary compilation, i.e. without conversion of the script text into system-dependent machine code. The user's browser interprets the script, that is, analyzes and immediately executes it. JavaScript is supported by the following browsers:
* Netscape Navigator (beginning with version 2.0)
* Microsoft Internet Explorer (beginning with version 3.0)
* Firefox
* Safari
* Opera
* Google Chrome
* Any other browser whose vendor licensed or implemented JavaScript.
Thus, most Internet users today have browsers that support JavaScript. That's why JavaScript is one of the most popular tools in the Web developer's arsenal.
Question: Where can I get JavaScript documentation?
Answer: Online JavaScript documentation is available at these sites:
* http://www.mozilla.org/js/language/ - Mozilla.org JavaScript Resources page
* http://msdn.microsoft.com/en-us/library/72bd815a.aspx - JScript at Development Tools and Languages section of MSDN Library.
* http://msdn.microsoft.com/en-us/library/hbxc2t98.aspx - JScript at Web Development and Scripting section of MSDN Library.
In addition, you can find JavaScript discussions, online tutorials, links, code examples, and hundreds of useful scripts at the following sites (of course this list is incomplete and serves only as a starting point):
* http://www.WebReference.com/programming/JavaScript/ - tutorials and in-depth discussions
* http://www.irt.org - FAQ collections in several categories, including JavaScript
* http://www.JavaScripts.com - lots of scripts and code examples
* http://www.JavaScripter.net/faq/ - this FAQ collection.
Question: How do I insert comments in JavaScript code?
Answer: JavaScript supports three different types of comments:
1. Multiple-line C-style comments. Everything between /* and */ is a comment, for example:
/* This is a comment */
/* C-style comments can span
as many lines as you like,
as shown in this example */
2. One-line comments of C++ style. These comments begin with // and continue up to the next line break:
// This is a one-line comment
3. One-line comments with the HTML comment-opening 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 usually found in the middle of JavaScript code. (The // comments are simpler and easier to read.) However, it is strongly recommended to use HTML comment
Question: How do I hide JS code from old browsers that do not support JavaScript?
Answer: To prevent old browsers from displaying your JS code, do the following:
1. Immediately after the opening
Thus, your HTML file will contain the following fragment:
Old browsers will treat your JS code as one long HTML comment. On the other hand, new JavaScript-aware browsers will normally interpret JS code between the tags (the first and last lines of your JS code will be treated by the JavaScript interpreter as one-line comments).
Question: If the user's browser cannot execute JavaScript code, can I display a warning for the user?
Answer: Yes, you can display a special warning for users of JavaScript-incapable browsers. Put your warning text between the tags . Here's an example:
JavaScript-enabled browsers will ignore everything between . Browsers that cannot execute JavaScript will display your message on the page. NOTE: The
Comments
Post a Comment