The address for this web page is:

On to the next lesson!


With JavaScript, you can begin to make your web pages really fun, by having programs that interact with the user and control the browser. Today's lesson provides an introduction to JavaScript.

The lessons on JavaScript have been prepared using information from:

JavaScript, The Definitive Guide, 3rd Edition, David Flanagan, O'Reilly Publishers.

In particular, the information for today's lesson comes primarily from pages 1 through 23 in this book.



What is JavaScript? JavaScript is a scripting language developed by Netscape to enable Web authors to design interactive sites. Javascript can interact with HTML source code, enabling Web authors to spice up their sites with dynamic content. JavaScript has object-oriented capabilities. The general-purpose core of the language has been embedded in Netscape Navigator, Internet Explorer, and other web browsers.

What is a scripting language? A script is a list of commands that can be executed without user interaction. A scripting language is a simple programming language to write scripts. Supposedly, scripting languages are "programming languages for non-programmers." It is true that non-programmers can use JavaScript for cookbook-style tasks; however, to call JavaScript a "scripting language" is a disservice. It is a full-featured programming language!

What does object-oriented mean? The term object-oriented describes a system that deals primarily with different types of objects, and where the actions you can take depend on what type of object you are manipulating.


Is JavaScript evolving? Absolutely. These lessons document JavaScript 1.2 .

What is JScript? Netscape invented JavaScript, and the name JavaScript is owned by Netscape. Microsoft's implementation of the language is called JScript. Versions of JavaScript and JScript are more or less compatible.

Are Java and JavaScript the same thing? NO. Java is a programming language from Sun Microsystems. Originally, JavaScript was called LiveScript; its name was changed at the last minute as a marketing ploy.

Are there other programming languages that can be embedded within a web browser? Yes. For example, VBScript is a variant of Microsoft's Visual Basic language which has many of the same features as JavaScript, but can only be used with Microsoft browsers.

Things you CAN do with JavaScript (J1c)

  • perform math computation; work with dates and times; compute sales tax on an on-line order
  • control document appearance and content; put current date and time in a document; display different content on different platforms
  • control the browser; pop up dialog boxes to display messages and get user input; open and close new browser windows; download and display contents of any URL in any window or frame
  • interact with HTML forms; read and write values in forms; verify that form input is correct before sending it to be processed by a CGI script on the server side
  • interact with the user; have different things happen based on what the user does; for example, display a special message in the status line when the mouse hits a certain link
  • read and write client state with cookies; A "cookie" is a small amount of data that is stored on the client's machine. Cookies are transmitted to and from the server to give information about the user, like "Has this user visited this site before?" JavaScript programs can read and write cookie values.

Things you CAN'T do with JavaScript (J1d)

  • can't draw graphics; However, it can dynamically generate images, tables, frames, forms, fonts, etc. for the browser to display.
  • can't read or write files; This is for security reasons. Would you want any old program from an unknown source running on your computer and messing with your files?
  • doesn't support networking. (A network is simply two or more personal computers, linked together.) However, JavaScript can download arbitrary URLs and send the contents of HTML forms to CGI scripts, email addresses, and Usenet newsgroups.


The following example illustrates many of the features of a typical JavaScript program. The output from this script is shown on J1f.

NOTE: In mathematics, 5! is read as "five factorial" and is defined by

5! = 5 x 4 x 3 x 2 x 1 = 120 .
Factorials are frequently used in Probability.
document.write("<H2>Table of Factorials</H2>");
for(i=1, fact=1; i<10; i++, fact*=i) {
	document.write(i + "! = " + fact);

Output from the Factorial Program (J1f)

Printable version of Index Card J1a

Printable version of Index Card J1b

Printable version of Index Card J1c

Printable version of Index Card J1d

Printable version of Index Card J1e

Printable version of Index Card J1f



On to the next lesson!
© 2001 Carol J.V. Fisher    All Rights Reserved