Abstract: A short introduction to JavaScript, its purpose, and its alternatives. Does not provide any description of how to code in JavaScript.
JavaScript is a programming language developed by NetScape communications corporation to permit more interactive HTML pages. HTML, the core language of the World-Wide Web, is a markup language: it describes data, not how to manipulate data. JavaScript was intended to extend HTML to make it more interactive.
What can you do with JavaScript? A great many things:
As teachers, why would we want to use JavaScript? For situations in which we need more interactive pages.
The folks at NetScape tried to make JavaScript usable by novices, but also familiar to "real programmers." Hence, it started as a small language (for novices), but it looks a lot like the programming language C (for programmers). JavaScript is not designed for large programs, and does not always do well with such. However, it does suffice for many small and medium-sized tasks.
JavaScript takes ideas from both the imperative and object-oriented paradigms. If you know an imperative language, such as Basic, Pascal, or C, much of JavaScript will seem familiar, although the syntax may be different. In particular, it supports traditional imperative components, such as
However, JavaScript adds "objects" to the mix. In a sense, objects are groups of data and related functions (sometimes called "methods"). Objects are similar to records in many imperative languages, although they are much more powerful. JavaScript also adds events and event handlers. In effect, you can write programs that say "when this happens, do this." However, you are limited in the events you can respond to.
JavaScript is primarily used as a client-side language, in that JavaScript programs are part of HTML pages, with the JavaScript code being exectued by the browser. However, Netscape also allows the use of JavaScript for writing CGI scripts in their LiveWire server. This tutorial will cover client-side issues.
Netscape introduced JavaScript with version 2.0 of their Navigator browser. As people began to develop programs and found deficiencies, Netscape extended and improved the language for version 3.0 of their Navigator browser (and are likely to extend it further for Coummunicator).
Because so many pages began to incorporate JavaScript scripts, Microsoft felt compelled to include support JavaScript in version 3.0 of their Internet Explorer browser. They call their version of JavaScript, JScript.
Unfortunately, the three versions of JavaScript differ somewhat in the commands and objects they support. In this tutorial, I'll be primarily covering the version supported by Navigator 3.0.
JavaScript is not the only way to make pages interactive, although it is one of the most convenient. Alternatives include CGI, Java, VBScript, and some advanced features of HTML.
Before the proliferation of web languages, the primary mechanism for building interactive pages was CGI, the common gateway interface. With CGI, HTML pages can send information to programs that reside on servers, and the servers can generate new pages based on that information. CGI script are ideal for search engines and other applications in which data reside on the server. However, pages using CGI scripts are not fully interactive; in effect, the user simply visits a sequence of pages that remain static within the viewer. JavaScript, because it runs on the user's computer, allows much more dynamic pages. On the other hand, it cannot easily obtain information from a server.
Sun Microsystems developed Java as an "industrial strength" language for program development. They soon realized that it was also appropriate for including programs within web pages. However, Java programs are generally independent of the surrounding page: they cannot manipulate the page, and the page cannot manipulate the Java programs. (A combination of Java and JavaScript now permits some page/application communication.)
VBScript is Microsoft's alternative to JavaScript. It is somewhat more readable than JavaScript, and builds on an installed base of Visual Basic users and programmers. However, it is supported only by Internet Explorer. There have also been questions raised as to the security of using VBScript.
Until the development of those languages, some of the "features" of
a programming language needed to be supported by HTML and the browser.
For example, there are tags in HTML to load another page after some
time progresses, or to test for browser support of some tags.
For example, there is a <noframes>
tag for browsers
that don't support frames.
Because JavaScript is supported by both major browsers, it is the choice for many applications. Because Netscape permits educational institutions to use Navigator without charge, JavaScript + Navigator form an appropriate combination for many institutions.
Exercise: Experimenting with interactive pages.
This page written by Samuel A. Rebelsky.
This page generated on 41 by SamR's Site Suite.