Sams Teach Yourself JavaScript in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- We Want to Hear from You!
- Reader Services
- Introduction
- Part I: Getting Started
- Hour 1. Understanding JavaScript
- Hour 2. Creating a Simple Script
- Hour 3. How JavaScript Programs Work
- Part II: Learning JavaScript Basics
- Hour 4. Using Functions and Variables
- Hour 5. Using Strings and Arrays
- Hour 6. Testing and Comparing Values
- Hour 7. Repeating Yourself: Using Loops
- Hour 8. Using Math and Date Functions
- Part III: The Document Object Model (DOM)
- Hour 9. Working with the Document Object Model
- Hour 10. Responding to Events
- Hour 11. Using Windows and Frames
- Hour 12. Getting Data with Forms
- Hour 13. Using Graphics and Animation
- Part IV: Moving on to Advanced JavaScript Features
- Hour 14. Creating Cross-Browser Scripts
- Hour 15. Creating Custom Objects
- Hour 16. Working with Sounds and Plug-Ins
- Hour 17. Debugging JavaScript Applications
- Part V: Working with Dynamic HTML (DHTML)
- Hour 18. Working with Style Sheets
- Hour 19. Using Dynamic HTML (DHTML)
- Hour 20. Using Advanced DOM Features
- Part VI: Putting It All Together
- Hour 21. Improving a Web Page with JavaScript
- Hour 22. Creating a JavaScript Game
- Hour 23. Creating DHTML Applications
- Hour 24. JavaScript Tips and Tricks
- Part VII: Appendices
- Appendix A. Other JavaScript Resources
- Appendix B. Tools for JavaScript Developers
- Appendix C. Glossary
- Appendix D. JavaScript Quick Reference
- Appendix E. DOM Quick Reference
Browsers and JavaScript
Like HTML, JavaScript requires a Web browser to be displayed, and different browsers may display it differently. Unlike HTML, the results of a browser incompatibility with JavaScript are more drastic: Rather than simply displaying your text incorrectly, the script may not execute at all, may display an error message, or may even crash the browser.
We'll take a quick look at the way different browsers—and different versions of the same browser—treat JavaScript in the following sections.
Netscape and Internet Explorer
Today's Web is dominated by two popular Web browsers: Netscape and Microsoft Internet Explorer. Netscape spent a few years being the more popular browser, but is now behind Internet Explorer in popularity; however, both are common enough that you should try to support them with your pages.
Versions of JavaScript
The JavaScript language has evolved since its original release in Netscape 2.0. There have been several versions of JavaScript:
- JavaScript 1.0, the original version, is supported by Netscape 2.0 and Internet Explorer 3.0.
- JavaScript 1.1 is supported by Netscape 3.0 and mostly supported by Internet Explorer 4.0.
- JavaScript 1.2 is supported by Netscape 4.0, and partially supported by Internet Explorer 4.0.
- JavaScript 1.3 is supported by Netscape 4.5 and Internet Explorer 5.0.
- JavaScript 1.5 is supported by Netscape 6.0 and Internet Explorer 5.5 and later.
Each of these versions is an improvement over the previous version and includes a number of new features. With rare exception, browsers that support the new version will also support scripts written for earlier versions.
ECMA, the European Computer Manufacturing Association, has finalized the ECMA-262 specification for ECMAScript, a standardized version of JavaScript. JavaScript 1.3 follows the ECMA-262 standard, and JavaScript 1.5 follows ECMA-262 revision 3.
Netscape is also working with ECMA on JavaScript 2.0, a future version that will correspond with the fourth edition of the ECMAScript standard. JavaScript 2.0 will improve upon earlier versions with a more modular approach, better object support, and features to make JavaScript useful as a general-purpose scripting language as well as a Web language.
Specifying JavaScript Versions
As mentioned earlier in this hour, you can specify a version of JavaScript in the <script> tag. For example, this tag specifies JavaScript version 1.3:
<script language="JavaScript1.3" type="text/javascript1.3">
There are two ways of specifying the version number. The old method uses the language attribute, and the new method recommended by the HTML 4.0 specification uses the type attribute. To maintain compatibility with older browsers, you can use both attributes.
When you specify a version number, this allows your script to execute only if the browser supports the version you specified or a later version.
When the <script> tag doesn't specify a version number, the browser assumes that the script is compatible with JavaScript 1.0. Since the core of the JavaScript language is unchanged since version 1.0, this is fine for most scripts.
JavaScript Beyond the Browser
While JavaScript programs traditionally run within a Web browser, and Web-based JavaScript is the focus of this book, JavaScript is becoming increasingly popular in other applications. Here are a few examples:
- Macromedia Dreamweaver, used for Web applications and multimedia, can be extended with JavaScript.
- Several server-side versions of JavaScript are available. These run within a Web server rather than a browser.
- Microsoft's Windows Scripting Host (WSH) supports JScript, Microsoft's implementation of JavaScript, as a general-purpose scripting language for Windows. Unfortunately, the most popular applications developed for WSH so far have been email viruses.
- Microsoft's Common Language Runtime (CLR), part of the .NET framework, supports JavaScript.
Along with these examples, many of the changes in the upcoming JavaScript 2.0 are designed to make it more suitable as a general-purpose scripting language.
Alternatives to JavaScript | Next Section

Account Sign In
View your cart