Home Scripts and Programs Glossary and Articles Other Resources Contact Us About Us
Adult Hosting
Budget Hosting
Coldfusion Hosting
Colocation
Dedicated Servers
Game Servers
Linux Hosting
Managed Hosting
Reseller Hosting
Ruby on Rails Hosting
Virtual Private Servers
Windows Hosting
Advertiser Login
Create An Account
More Info
JavaScript
JavaScript is an object-based scripting programming language based on the concept of prototypes. The language is best known for its use in websites, but is also used to enable scripting access to objects embedded in other applications.

Despite the name, JavaScript is only distantly related to the Java programming language, the main similarity being their common debt to the C programming language. JavaScript has far more in common with the Self programming language.

JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape.

JavaScript was originally developed by Brendan Eich of Netscape Communications Corporation under the name Mocha, then LiveScript, and finally renamed to JavaScript. The change of name from LiveScript to JavaScript roughly coincided with Netscape adding support for Java technology in its Netscape Navigator web browser. JavaScript was first introduced and deployed in the Netscape browser version 2.0B3 in December of 1995. When web developers talk about using JavaScript in Internet Explorer, they are actually using JScript. The choice of name proved to be a source of much confusion.

As of 2005, the latest version of the language is JavaScript 1.6, which corresponds to ECMA-262 Edition 3 like JavaScript 1.5, except for Array extras, and Array and String generics. ECMAScript, in simple terms, is a standardized version of JavaScript. Mozilla versions since 1.8 Beta 1 also have partial support of E4X, which is a language extension dealing with XML, defined in the ECMA-357 standard.

JavaScript is a prototype-based scripting language with a syntax loosely based on C. Like C, it has the concept of reserved keywords, which (being executed from source) means it is almost impossible to extend the language without breakage.

Also like C, the language has no input or output constructs of its own. Where C relies on standard I/O libraries, a JavaScript engine relies on a host environment into which it is embedded. There are many such host environment applications, of which web technologies are the most well known examples. These are examined first.

JavaScript embedded in a web browser connects through interfaces called Document Object Model (DOM) to applications, especially to the server side (web servers) and the client side (web browsers) of web applications. Many web sites use client-side JavaScript technology to create powerful dynamic web applications. It may use unicode and can evaluate regular expressions (introduced in version 1.2 in Netscape Navigator 4 and Internet Explorer 4). JavaScript expressions contained in a string can be evaluated using the eval function.

One major use of web-based JavaScript is to write functions that are embedded in or included from HTML pages and interact with the DOM of the page to perform tasks not possible in static HTML alone, such as opening a new window, checking input values, changing images as the mouse cursor moves over, etc. Unfortunately, the DOM interfaces in various browsers differ and don't always match the W3C DOM standards. Different browsers expose different objects and methods to the script. It is therefore often necessary to write different variants of a JavaScript function for the various browsers, though this situation is improving. Major design methodologies using JavaScript to interact with DOM include DHTML, Ajax, and SPA.

Outside of the Web, JavaScript interpreters are embedded in a number of tools. Adobe Acrobat and Adobe Reader support JavaScript in PDF files. The Mozilla platform, which underlies several common web browsers, uses JavaScript to implement the user interface and transaction logic of its various products. JavaScript interpreters are also embedded in proprietary applications that lack scriptable interfaces. Dashboard Widgets in Apple's Mac OS X v10.4 are implemented using JavaScript. Microsoft's Active Scripting technology supports JavaScript-compatible JScript as an operating system scripting language. JScript .NET is a CLI-compliant language that is similar to JScript, but has further object oriented programming features.

Each of these applications provides its own object model which provides access to the host environment, with the core JavaScript language remaining mostly the same in each application.

Depending on the development environment debugging used to be difficult. Since errors in JavaScript only appear in run-time (i.e., there is no way to check for errors without executing the code), and since JavaScript is interpreted by the web browser as the page is viewed, it may be difficult to track the cause for errors. However nowadays both Internet Explorer and the Gecko-based browsers come with a reasonably good debugger. Gecko browsers use the Venkman debugger, while for Internet Explorer there are two versions: the Microsoft Script Debugger (free), and the Microsoft Script Editor (paid). Also, since the arrival of integrated toolbars and plugins, more and more support for JavaScript debugging is becoming available. The Gecko browsers have a native DOM inspector; for Internet Explorer a DOM inspector is integrated in the Web Developer toolbar.

Scripting languages are especially susceptible to bugs for the inexperienced programmer. Because JavaScript is interpreted, loosely-typed, and has varying environments (host applications), implementations and versions the programmer has to take exceptional care to make sure the code executes as expected.

Each script block is parsed separately. On pages where JavaScript in script blocks is mixed with HTML, syntax errors can be identified more readily by keeping discrete functions in separate script blocks, or (for preference), using many small linked .js files. This way, a syntax error will not cause parsing/compiling to fail for the whole page, and can enable a dignified die.

There is no real relationship between Java and JavaScript; their similarities are mostly in syntax (that is, both derived from C). Their semantics are quite different: notably, their object models are unrelated and largely incompatible. Also worth mentioning is Microsoft's own VBScript, which, like JavaScript, is mainly used in web pages. VBScript has syntax derived from Visual Basic and is only available on Internet Explorer.

Due to the success of JavaScript, Microsoft developed a compatible language known as JScript. JScript was first supported in the Internet Explorer browser version 3.0 released in August, 1996. When web developers talk about using JavaScript in the IE browser, they usually mean JScript.

The need for common specifications for the two languages was the basis of the ECMA 262 standard for ECMAScript (see external links below), three editions of which have been published since the work started in November 1996 (and which in turn set the stage for the standardization of C# a few years later). Implementations of ECMAScript include JavaScript, JScript, and DMDScript. One term often related to JavaScript, the Document Object Model (DOM), is actually not part of the ECMAScript standard; it's a separate standard, developed by the W3C, closely related to XML.

ActionScript, the programming language used in Macromedia Flash, bears a resemblance to JavaScript. ActionScript has similar syntax to JavaScript, but the object model is dramatically different.

JSON, or JavaScript Object Notation, is a general-purpose data interchange format that is defined as a subset of JavaScript.

JavaScript OSA (JavaScript for OSA, or JSOSA), is a Macintosh scripting language based on the Mozilla 1.5 JavaScript implementation, SpiderMonkey. It is a freeware component made available by Late Night Software. Interaction with the operating system and with third-party applications is scripted via a MacOS object. Otherwise, the language is virtually identical to the core Mozilla implementation. It was offered as an alternative to the more commonly used AppleScript language.

Of only historical interest now, ECMAScript was included in the VRML97 standard for scripting nodes of VRML scene description files.


 
Site Map | Policies | Contact