What is JavaScript?

Here's the short answer: JavaScript is the leading client-side scripting language for use on Web pages.

So, what does that mean?

JavaScript is a scripting language, and scripting languages are easier to learn and use than traditional programming languages.

JavaScript works on the client side, which means that it runs on the user's computer and not on the Web server. The browsers interprets JavaScript statements embedded directly in an HTML page.

JavaScript is designed for use on Web pages and is closely integrated with HTML.

JavaScript statements embedded in an HTML page can recognize and respond to User Events such as Mouse Clicks, Form Input, and Page Navigation.

For example, you can write a JavaScript function to verify that users enter valid information into a form requesting a telephone number or zip code. Without any network transmission, an HTML page with embedded JavaScript can interpret the entered text and alert the user with a message dialog if the input is invalid. Or you can use JavaScript to perform an action (such as play an audio file, execute an applet, or communicate with a plug-in) in response to the user opening or exiting a page.

Here's the long answer:

  • A scripting language

Scripting languages have been in use long before the Web came around. In Unix environment, scripts have been used to perform repetitive system administration tasks and to automate many tasks for less computer-literate users. In addition, scripting languages are the basis of much of the cgi-bin programming that is currently used to add limited form of interactivity to Web pages.

Of course, this still doesn’t tell what the main advantages of scripting languages are. Like all scripting languages, JavaScript is interpreted, which provides an easy development process; it contains a limited and easy-to-learn command set and syntax; and it is designed for performing a well-defined set of tasks.

  • Designed for Simple, Small Programs

Because JavaScript is a scripting language, it is well suited to implementing simple, small programs. For instance, JavaScript would ideally be suited to developing a unit conversion calculator between miles and kilometers or pounds and kilograms. These tasks can be easily written and performed at acceptable speeds with JavaScript and would be easily integrated into a Web page. A more robust language such as Java would be less suitable for the quick development and easy maintenance of these types of applications.

By contrast, JavaScript would not be well suited to implementing a distributed CAD document display and manipulation environment. While eventually JavaScript will be a tool for integrating this type of Java applet or plug-in into a Web page, to attempt to develop the actual applet in JavaScript would at best, difficult and inefficient and, more likely, would be impossible.

  • Performs Repetitive Tasks

Just as JavaScript is suited to producing small programs, it is especially well designed for repetitive, event-invoked tasks. For example, JavaScript is ideal for calculating the content of on field in a form based on changes to the data in another field. Each time the data changes, the JavaScript program to handle the event is invoked, and the new data for the other field is calculated and displayed.

  • Designed for Programming User Events

Because of the way in which JavaScript is integrated into the browser and can interact directly with the HTML pages, JavaScript makes it possible to program responses to user events such as mouse clicks and data entry in forms.

For instance, a JavaScript script could be used to implement a simple help system. Whenever the user points a button or a link on the page, a helpful and informative message can be displayed in the bar at the bottom of the browser window.

This adds interactivity to Web pages, makes forms dynamic, and can decrease the bandwidth requirements and server load incurred by using forms and CGI programming.

  • Easy Debugging and Testing

Like other scripting languages, JavaScript eases development and trouble-shooting because it is not compiled. It is easy to test program code, look at the results, make changes, and test it again without the overhead and delay of compiling.

  • Live Connect

LiveConnect enables communication between JavaScript and Java applets in a page and between JavaScript and Plug-ins loaded on a page. JavaScript can trigger events in Java applets, and Java applets can call JavaScript methods and functions.

Summary of JavaScript Strengths

JavaScript offers several strengths to the programmer including a short development cycle, ease of learning, and small size scripts. These strengths mean that JavaScript can be easily and quickly used to extend HTML pages already on the web.

  • Quick Development – because of JavaScript does not require time-consuming compilation, scripts can be developed in a relatively short period of time. This is enhanced by the fact that most of the interface features, such as dialog boxes, forms, and other GUI elements, are handled by the browser and HTML code. JavaScript programmers don’t have to worry about creating or handling these elements of their applications.
  • Easy to Learn – while JavaScript may share many similarities with Java, it doesn’t include the complex syntax and rules of Java. By learning just a few commands and simple rules of syntax, along with understanding the way objects are used in JavaScript, it is possible to begin creating fairly sophisticated programs.
  • Platform Independence – Because the WWW, by its very nature, is platform-independent, JavaScript programs created for the browsers are not tied to any specific hardware platform or operating system. The same program code can be used on any platform for which a browser is available.
  • Small Overhead – JavaScript programs tend to be fairly compact and are quite small, compared to the binary applets produced by Java. This minimizes storage requirements on the server and download times for the user. In addition, because JavaScript programs usually are included in the same file as the HTML code for a page, they require fewer network accesses.

Weakness of JavaScript

As would be expected, JavaScript has it own unique weaknesses. These include limited set of built-in methods, the inability to protect source code from prying eyes.

  • Limited Range of Built-in Methods - however, more and more Methods are being introduced in the newer JavaScript versions.
  • Generally, only Client-Side script
  • No Code Hiding