Javascript Lesson 01

What is Javascript

< BACK   |  NEXT >

 

The JavaScript language was developed by the Netscape Communications Corporation and is a trademarked name. It is a cross-platform, object-based scripting language that was originally designed for use in Netscape Navigator. Indeed, versions 2.0, and later, of Navigator can interpret JavaScript statements that are embedded within HTML code. When a request is made to see a page, the HTML code that defines the requested page along with the embedded JavaScript statements, are sent by the server to the client. Navigator interprets the HTML document and executes the JavaScript code. The resultant page is displayed for the client. It is important to understand that this interpretation occurs on the client-side rather than the server-side.

After the success of JavaScript in Navigator 2.0, the Microsoft Corporation was quick to create a clone of JavaScript, called JScript, which is a trademarked name, that is designed to run inside the Microsoft Internet Explorer. In truth, except for a few minor differences, JScript is essentially a carbon copy of JavaScript.

The latest versions of JavaScript and JScript are compliant with the European Computer Manufacturing Association's ECMAScript Language Specification (ECMA-262 standard, for short). Note that the name for this EMCA-262 language is ECMAScript. However, Netscape will continue to use the name, JavaScript and, likewise, Microsoft will continue to use the name, JScript. It is important to understand that the EMCA-262 standards sets minimum compatability requirements. You should expect current and future versions of both JavaScript and JScript to also contain additional proprietary features, beyond the minimum reqirements, designed to woo the developer to favor one language over the other. Fortunately, both Microsoft and Netscape have promised to submit new features to ECMA for inclusion in the evolving EMCA-262 standard. Many older browsers are, of course, still very happily utilizing older, non-compliant versions of these scripting languages.

JavaScript is a simple to comprehend, easy to use, general purpose scripting language. When used in conjunction with a Web browser's Document Object Model (DOM), it can produce powerful dynamic HTML browser-based applications which also can feature animation and sound.


Javascript Versions

There are several versions of JavaScript supported by certain browsers and browser versions.Unfortunately, this can often lead to confusion and incompatibilities. Since Netscape originally introduced JavaScript, JavaScript 1.0 was the language specification supported in Netscape Navigator 2.0. Subsequently, Navigator 3.0 supported new enhancements which comprised JavaScript 1.1. At present, Navigator 4.0 supports JavaScript 1.2.

In parallel, Microsoft attempted to support JavaScript 1.0 in their Internet Explorer 3.0 browser. Known as "Jscript," Microsoft's initial JavaScript support was unreliable and buggy. A push to standardize the language resulted in an "official" version of JavaScript sanctioned by the ECMA. Internet Explorer 4.0 includes robust support for the ECMA standardized JavaScript, which, although it shares much in common with Netscape's JavaScript 1.2, is not exactly equivalent.

While programming for any single version of JavaScript is relatively simple, writing code which functions across disparate versions, most notably Navigator 4 and MSIE 4, is one of the major challenges and topics of discussion in JavaScript programming at this time.


Where do you put the Javascript?

JavaScript code is typically embedded into an HTML document using the SCRIPT tag. You are free to embed as many scripts into a single document as you like, using multiple SCRIPT tags. A script embedded in HTML with the SCRIPT tag uses the format:

<script language="JavaScript">
  <!--
    document.write("Hello World!");
  //-->
</script>

The LANGUAGE attribute is optional, but recommended. You may specify that a section of code only be executed by browsers which support a particular version of JavaScript; for instance:

<script language="JavaScript1.2">

Another attribute of the SCRIPT tag, SRC, can be used to include an external file containing JavaScript code rather than code embedded into the HTML:

<script language="JavaScript" src="corefunctions.js">
</script>

The external file is simply a text file containing JavaScript code, and whose filename ends with the extension ".js". Note that although some version 3 browsers support the SRC attribute, it only functions reliably across platforms in the version 4 browsers.

Scripts can be placed inside comment fields to ensure that your JavaScript code is not displayed by old browsers that do not recognize JavaScript. The markup to begin a comment field is <!-- while you close a comment field using //-->. This practice is certainly optional, but considered good form when your page is likely to be visited by older browsers. Certainly, as older browsers fade away, this practice will likely become unnecessary.