About JavaScript
JavaScript was developed from a language called LiveScript, which was developed by Netscape for use in its early browsers. JavaScript source code is embedded within the HTML code of web pages and interpreted and executed by the browser when the page is displayed.
Using JavaScript, you can add extra functionality to your web pages. Examples include
Change the way page elements are displayed
Add animation and other image effects
Open pop-up windows and dialogs
Check the validity of user-entered data
Nearly all modern browsers support JavaScript, though with a few differences in some commands. Where these occur, they are described in the text.
Caution
![]() | Although JavaScript is likely to be supported by your browser, it is usually possible for the browser options to be configured so as to disable its use. If you find that you cannot get any JavaScript commands to work, consult your browser's help files to find out how to check whether JavaScript is correctly enabled. |
Note
![]() | Microsoft's Internet Explorer browser actually runs a proprietary Microsoft language called Jscript, instead of JavaScript. The two are, however, virtually identical and therefore largely compatible. Where differences occur, they are described in the text. |
Why Do I Need To Know About JavaScript?
The j in Ajax stands for JavaScript; you use functions written in this language and embedded within your web pages to formulate Ajax server calls and to handle and process the response returned from the server.
What Is (and Isn't) Covered in This Lesson
There is no room here for an exhaustive guide to all JavaScript's functions. Instead this lesson concentrates on those aspects of the language necessary for later developing Ajax applications.
After completing this lesson, you'll have experience with the following:
Embedding JavaScript commands and external JavaScript files into web pages
Using some of the common JavaScript commands
Using event handlers to launch JavaScript commands
Working with JavaScript variables and objects
Abstracting JavaScript commands into functions
Tip
![]() | For a much more thorough course in JavaScript, try Sams Teach Yourself JavaScript in 24 Hours by Michael Moncur. |
JavaScript Basics
JavaScript commands can be embedded directly into HTML pages by placing them between <script> ...</script> tags. It is also common for JavaScript functions to be kept in a separate file on the server (usually with a file extension .js) and linked to HTML files where required, by placing a line like this into the head of the HTML file:
<SCRIPT language="JavaScript" SRC="myJS.js"></SCRIPT>
This allows you to call any JavaScript within the file myJS.js, just as if that source code had been typed directly into your own web page.
Tip
![]() | Placing JavaScript functions into external files allows them to be made available to a number of different web pages without having to retype any code. It also makes them easier to maintain because the latest version is automatically linked into the calling HTML page each time that page is requested. It is possible to build up substantial JavaScript libraries in this way, linking them into web pages when their particular functions are required. |