Language Choices for Client-Side Scripting
Many different languages are available for writing client-side scripts. Language choice is generally based on the specific features or characteristics of the language, adherence to company- or project-wide standards, or simply personal preference. This article briefly discusses the most popular languages for client-side scripting.
JavaScript
JavaScript is by far the most widely used language for client-side scripts. In large part, this is due to three things: JavaScript was the first scripting language for Web browsers to gain popularity, it alone has formed the basis of a standard, and it is the only language supported natively by the two browsers that share virtually the entire Web browser marketNetscape Navigator and Microsoft Internet Explorer.
JavaScript was the original client-side scripting language for the Web, invented by Netscape for its Navigator Web browser. JavaScript began life as LiveScript, a lightweight language based on C, C++, and Perl. However, LiveScript did not garner much interest in the Web developer community due to the focus on Java, so Netscape changed the name to JavaScript and released Version 1.0 for Navigator 2.0.
JavaScript offers a core object model (see Table 1) that provides developers with a set of basic data structures and functionality. This core is extended in both server- and client-side versions. For example, client-side JavaScript extends the core object model with support for the browser and document object models.
Table 1 Core JavaScript Objects
Object |
Description |
Array |
The built-in Array object offers methods for managing and manipulating arrays of values. |
Boolean |
The Boolean object is used to evaluate a value or expression as a primitive boolean true or false value. |
Date |
The built-in Date object offers a rich set of functionality for working with dates and times. |
Function |
The Function object provides a way of evaluating a string of JavaScript at runtime as a function. This differs from the function statement, which is evaluated and compiled once, because the object is re-evaluated each time it is called. |
Math |
The built-in Math object provides constants and functions for mathematical calculations. |
Number |
The Number object is used to represent numerical constants, such as infinity. |
String |
The String object offers a large set of functions for manipulating character strings. |
Microsoft soon followed Netscape's example by adding support for JavaScript to Internet Explorer 3.0. Microsoft's implementation, JScript, is an enhanced version of JavaScript, offering proprietary extensions that leverage the special capabilities of Internet Explorer. However, the scripting engine in Internet Explorer supports cross-browser compatible scripts. Web developers can leverage the enhanced features of Internet Explorer by using the JScript keyword in the <script> tag, as shown in the following code:
<script language="JScript">
However, these scripts are not supported in Netscape Navigator. Scripts that must operate correctly on the greatest range of browsers must use the JavaScript keyword.
<script language="JavaScript">
ECMA-262or ECMAScript, as it is commonly calledis a standard for scripting languages published by the European Computer Manufacturer's Association. ECMA is a nonprofit international industry association that is engaged in the standardization of information and communications technologies. Formed in 1961, ECMA has published more than 300 standards documents and numerous technical reports, and ECMA standards have served as a base for many other European and international standards.
ECMA-262 is based on a joint submission from Netscape and Microsoft. As such, ECMAScript incorporates elements of both JavaScript and JScript, and it has been well received by the industry. Netscape's first implementation of ECMA-262 was JavaScript 1.1, and Microsoft's was JScript 3.0. The implementations of JavaScript and JScript in the latest versions of Navigator/Communicator and Internet Explorer are fully compliant with ECMA-262. In addition, the International Standards Organization (ISO) has approved the ECMA-262 specification as ISO-16262.