JavaScript Intro



index
Disabled back button Next Section
printable version

Section 1: Introduction

JavaScript was created to extend the functions a browser can perform.

JavaScript enables the programmer to manipulate HTML documents (checking form fields, submitting forms, creating dynamic pages, and such) and the browser itself (directing the browser to load other HTML pages, display messages, and so on).


Originally called LiveScript, JavaScript is a cross-platform, client-side scripting language for use on the web.


JavaScript is an interpreted language.


JavaScript is an event-driven programming language.


It should be noted that despite the name, JavaScript does not share much of anything in common with Java (other than similar names, of course).


Components of a web page
Section 2: Historical Context and Standards

JavaScript was developed by Netscape to run in Netscape Navigator and first appeared in Netscape 2.0 (Notable browser list).

Shortly thereafter, Microsoft countered with their own product called JScript (now deprecated).

Google is now trying to replace it with Dart.

In response to these competing scripting languages the European Computer Manufacturers Association (ECMA), an international standards body, proposed a standard that, to avoid the politics of appearing to side with any one major browser company, was dubbed ECMAScript.

Section 3: Uses of JavaScript

Since JavaScript is a client-side programming language, when you download a page with JavaScript in it, that script is run on your computer inside your web browser.

Most of what JavaScript can do revolves around monitoring or altering the content of web pages and interacting with the user through the web browser interface.

One thing JavaScript can do is change the content of a document being displayed in the web browser.

For instance, JavaScript allows you to dynamically change the appearance of something when you move the mouse over it. Which, by the way, you can do with this paragraph in most any recent browser.

It can even make elements appear and disappear from a document. (Hover over this paragraph makes the following paragraph vanish.)

Now you see it....

JavaScript allows you to generate pop-up windows.

JavaScript also allows you to rewrite or even generate what is displayed on the screen.

Section 4: Browser Control

JavaScript includes commands that allow you to control the content being displayed in the browser.

It can be used to open new documents in a window, or to return to a previously visited document. In the above example it was used to open a new document in a new window and then close the window when the "Close Window" button is clicked.

JavaScript can also be used to pass information between windows and frames. JavaScript is also commonly used for creating interactive menus. Most of the class web pages use JavaScript driven menus, and the notes pages get their functionality from extremely complex JavaScript code.

Section 5: Data Handling

JavaScript can be used to process data.

Another way of interacting with forms is validating data before you submit an online form.

It can also be used to keep track of someone shopping on an online catalog and store information on things they want to buy until they are ready to check out.

The only real limit on what it can do in validating and processing online form data is that JavaScript is a slow language and complicated programs not only take a long time to download, but also a long time to run.

Section 6: Limitations
Section 7: Information Assurance

Most of the limitations on JavaScript are limitations that have been set for security reasons. JavaScript is reputed to be the safest scripting language out there. All known security loops have been closed.

By maintaining a very limited set of abilities for the language, it becomes very hard for anyone to try to assault your computer with malicious JavaScript code. (Perhaps the worst they can do is write script that opens a whole string of new windows containing the same script, causing your browser windows to multiply until your browser or computer crashes.)

Although there is no guarantee that new security holes won't surface, it is still one of the safest languages available because of these restrictions.

Notes on why some people disable JavaScript.

Section 8: Script Placement

Depending on the nature of the script, the code will be placed either in the <head> element or in the <body> element where the script is being used.

No matter where they are used, scripts are placed inside a <script> tag.

Take a look at the JavaScript example below:

<script>
   alert("Hello World!");
</script>

When placed in the <body> element of a page, the code above will result in a popup that announces "Hello World!"

Scripts placed in the <head> tag are executed when they are called, or when an event is triggered. When you place a script in the <head> tag, you will ensure that the script is loaded before anyone uses it.

Scripts to be executed when the page loads go in the <body> section. When you place a script in the <body> section it generates the content of the page.


Linking External JavaScript Files

Often you need to run the same JavaScript on several pages, without having to write the same script on every page. In such cases, it's possible to use JavaScript in an external file.