What is JavaScript
Volume Number: 14
Issue Number: 5
Column Tag: Scripting
What is JavaScript?
by Dori Smith
As these examples show, it's just a simple web scripting
language
What's JavaScript? What's the difference between JavaScript and Java? Isn't
JavaScript just a simplified version of Java? These are common questions that I get all
the time.
Netscape originally invented a simple scripting language called LiveScript, which was
to be a proprietary add-on to HTML. When Sun's new language Java became
unexpectedly popular, Netscape was quick to jump on the Java bandwagon, and
re-christened their scripting language JavaScript. Outside of the first four letters,
there are almost no other similarities between the two.
Microsoft then added their own version of JavaScript to Internet Explorer, which they
named JScript. Unfortunately, the two were not identical, so Netscape then attempted
to straighten matters out by turning JavaScript over to ECMA, a Switzerland-based
standards body. This gave three main versions of JavaScript-based languages:
JavaScript, which works primarily with Netscape's browsers, JScript, which works
with Internet Explorer, and ECMAScript, with which no browser is completely
compatible. Netscape and Microsoft have both stated that future versions will match
the ECMAScript standard, which should lead to convergence. However, as the
most-used features are common to all, compatibility is not an issue unless you are
trying to use JavaScript to control DHTML.
JavaScript is growing in popularity due to its simple learning curve relative to the
amount of power it provides. Complete non-programmers are able to add a little bit of
interactivity to their web pages without buying an IDE or sweating over why a
program won't compile. There are numerous Web sites which contain any number of
scripts available for the taking, and Netscape has fairly complete documentation on
their site. And of course, there's the always useful ability to view the source of Web
pages.
Syntax & Basics
The syntax of JavaScript will be simple to anyone who has ever programmed in an
object oriented language. The primary object is the window, which is at the top of the
hierarchy. Under that are the document, frame, location, history, and navigator
objects. In turn, the document object contains anchors, applets, embeds, forms,
images, and links, each of which is an array of objects. So, a reference to the first
image on a page would be to self.document.image[0], although it is preferable to use
names instead of numbers for clarity.
JavaScript is not a stand-alone language, but rather a scripting add-on to HTML.
JavaScript is added to HTML commands by use of the