JavaScript is one of a new breed of Web languages called scripting languages. Scripting languages make it easy for nonprogrammers to improve a Web page. JavaScript was originally developed by Netscape Corporation for use in its browser Netscape Navigator. It includes a convenient syntax, flexible variable types, and easy access to the browser's features. It can run on the browser without being compiled. the source code can be placed directly into a Web page.

Introduction to JavaScript - Scripting Language

You can program in JavaScript easily. you can use the same editor you use to create HTML documents to create JavaScript, and it executes directly on the browser. JavaScript can work directly with HTML elements in a Web page. It is also simple to use, and you can do quite a bit with just a few JavaScript statements.

Although JavaScript does not have any features that eclipse Java, it adds some conveniences as well as simplifying programming. It provides better integration with the browser. the key differences from Java include the following:
  1. JavaScript can be combined directly with HTML.
  2. The JavaScript language structure is simpler than that of Java.
  3. The JavaScript interpreter is built into a Web browser, namely the Netscape navigator.
  4. JavaScript is supported on more platforms than Java.


JavaScript programs are simple ASCII text files. You can keep them as separate files or include the javaScript functions within an HTML page. The <SCRIPT> tag, an extension of HTML supported by the browser Netscape, enables you to include one or more JavaScript functions on the page. a sample HTML document embedding a JavaScript function shows below.

Note that the tag for JavaScript is shown by the statement <SCRIPT LANGUAGE="JavaScript">. Moreover, the function of JavaScript is then used for writing the output using the statement:
document.write("Here is JavaScript Output.")


Some characteristics of javaScript are as follows:
  1. The JavaScript language is interpreted rather than compiled. Changing a script is as simple as changing an HTML page.
  2. Rather than creating objects and classes, you can do quite a bit by simply accessing existing objects in JavaScript.
  3. Variables are loosely typed. you do not need to declare variables before their use, and most conversions (such as numeric to string) are handled automatically.
  4. Event handlers enable a JavaScript function to execute an action is performed on part of the HTML document.


JavaScript is an object-oriented language and it can use objects. An object can store multiple values and can also include actual JavaScript code. JavaScript also includes objects that enable you to access features of the browser directly. These objects represent actual elements of the browser and the Web page, such as windows, documents, etc. you can also control the browser with JavaScript.

For example, it is possible to include a 'back button on your Web page that will send the user back to the previous page just like the browser's back-arrow button. because JavaScript is supported by Netscape on all the available platforms, it is supported more widely than Java. The functionality is provided on the following platforms:
  1. Windows 3.1, using the 16-bit version of Netscape Navigator.
  2. Windows 95 or Windows NT, using the 32-bit version of Navigator and Internet Explorer.
  3. Macintosh System 7 or higher, using the Macintosh version of Web Browser.
  4. Most versions of UNIX, using the X Window version of Navigator and Internet Explorer.


Dynamic Information Inclusion

JavaScript can be used by making some of the text dynamics. As a simple example, you could display an appropriate greeting "good morning" or "good evening", depending on the time. Because you can use and control the HTML itself, you can extend this by dynamically choosing graphics or links using JavaScript. Thus, depending on the user, the time, or any factor, you can present the appropriate page.

Validating Forms

Whenever a user enters data into the form, and presses the Submit button, the server, using a CGI program, responds to the information. This is useful, but it is not very interactive because, before you can receive a response, you have to wait for the data to travel to the server and back. Javascript can add an instant response to a Web form. you still can not send the data to the server until the Submit button is pressed, but JavaScript can act on the data in the meantime.

For example, you could fill out a loan application online and, as you fill it out, instantly get feedback about the kind of payment the loan will require. After you are satisfied with the application, you can then submit it to the server. the biggest difference between JavaScript and CGI is that CGI works on the server and JavaScript works on the user's own machine (the client). CGI is most useful for sending data to the server and sending server data back to the user.

Making Web Pages Interactive

JavaScript can be used to give the user some control on the page. For example, you could have a background on/off button to control the display of the background, or a button to toggle the display of a table of contents.


Security Considerations

As JavaScript has been developed, there have been several concerns about security. A JavaScript script can read your URL history and report it to the remote site. Your e-mail address can be read and used to send an e-mail without your knowledge. A list of files on your hard disk can be obtained. URLs you visit can be logged by a script and transmitted. if you have the latest version of Netscape, you are safe from these problems.

Source Code is Accessible

Another problem with javaScript is that, currently, there is no way to use JavaScript on your Web page without making the script source available to anyone who wishes to copy it. This means that you might spend hours working on a script, only to find that people have copied it onto their own Web pages.

Lack of Network Communication

JavaScript has no facilities for communicating between the Web browser and the HTTP server. This means that although you can use JavaScript to manipulate data the user enters in a form, you can not send the resulting data back to the server. you can combine JavaScript with another Web language to solve this problem. CGI is the easiest way to do this.

Limited Graphics and Multimedia Capabilities

JavaScript is a scripting language. you can include graphics in a Web page and use JavaScript to specify which ones to use.

Limited Speed

The current implementation of JavaScript is a bit slow. any complex calculation or manipulation of HTML tends to run at a slow speed.


We already know that JavaScript allows Web designers to add functionality and interactivity to Web pages that otherwise could not be gained with HTML. It can create interactive forms or make text turn colors when a mouse moves over it. JavaScript is also an interpreted language, which means that its commands are executed by the browser in the order in which the browser reads them.

Javascript commands are put directly into the HTML file that creates a Web page. Depending on the script being run, the commands can be put into several places in the file. Often the commands are put near the top of the file. Special codes are set of the commands, altering the browser that they are JavaScript commands. if the commands are put before the HTML <body> tag at the top of the file, then the script will be able to start executing which the HTML page is still loading.

The heart of the way that JavaScript works is to take action on objects. These actions are called methods. Using this basic concept, JavaScript can be used for a wide variety of sophisticated interactive features.