www.webdeveloper.earthweb.com/webjs/article.php/3726231

Back to Article

What is JavaScript?
By
February 5, 2008

JavaScript is the workhorse of the common Internet page. It is used to carry out the higher, more advanced functions inherent to more and more of today's web pages. With it you can interact with the user input for an HTML FORM control, for instance. There are many visual effects you can accomplish using JavaScript such as flying banners, fades, and other effects. Your skill level and creativity are the only limits to what you can accomplish. I'll give you the skills; you have to provide the imagination.

After the creation and widespread acceptance of the Internet, the makers of the standards we use today realized that there was a huge hole in the capabilities of the online web browser. CGI (Common Gateway Interface) scripting had become the practice for processing user input, but it took its toll on the servers used to process the commands, raising the cost of doing business. This cost was addressed and partly solved with the creation of JavaScript, which was first intended to relieve server load by processing some of the common user input into a form the server could use. Some examples are verification and validation of user input. Verifying a five digit zip code or six digit postal code are very common applications of JavaScript. The server load was therefore reduced by executing some of the code - that was previously in the CGI script on the server - on the user's machine.

JavaScript is Object Oriented, meaning that you create an object with a certain set of properties that does a certain thing. You then re-use it as many times as you have a need for. This object oriented architecture is what all new and semi-new languages are migrating to - it solves many of the problems of the older "inline" languages which start processing from the top and work down the list of commands. These inline languages are slow and tedious, and are of limited capability. Object Oriented languages solved the problems inherent to this form of programming by making its objects available to the rest of the script.

The modular programming style of the Object Oriented approach involves keeping about three different rules in mind. Take a look.

  • Create your object with an eye toward re-using it later.
  • Identify common, repetitive tasks and make the object to do them.
  • These identified common tasks, now objects, are placed in external library files of .js or .mocha extensions.

Placing the re-usable code in an external file makes it available to the rest of your site content through the use of an HTML LINK tag. This is advantageous because you need only change the contents of one file to make a change or revision. The alternative is to place the script in every file, creating the need to make changes or revisions in every single file on your web site that uses the code. You can see the advantages of this approach, which was inspired by the CSS external style sheet.

Another great advantage of JavaScript is its platform independence - it can run on almost any machine created because its specifications don't change from platform to platform. There are some inherent inconsistencies, but as a whole the language is interpreted in much the same way. Keep in mind that errors by programmers create a huge array of some very strange inconsistencies on each platform. Some can be used in an advantageous way, while others severely limit the capabilities of certain objects.

Next article in series:  JavaScript Security