JavaScript

Introduction
JavaScript formerly known as ECMA_Script is a widely-used web scripting language that is especially suited for dynmic web development and can be embedded into HTML, PHP, asp etc.

Example:Embedding JavaScript in HTML Example  alert("Hallo, I'm a JavaScript Embedded in HTML!"); < /html> Example 2: Embedding JavaScript in PHP           Item  Quantity           Jeans trouser 300        "; ?>  alert("The table and text are generated by PHP code");  JavaScript is a client-side scripting language. These scripts are executed on the client computer and not the server. JavaScript runs on different platforms and is compatible with almost all web browsers used today.

It is loosely typed meaning that a variable can hold data of different types and it is not a must for variables to be declared before use.

Scripting Languages
There are several scripting languages. Examples:
 * 1) VBScript - Client side
 * 2) php - Server side
 * 3) JavaScript - Client side. And many more

Specifying Scripting Language
Syntax: script statements or script statements

You can specify JavaScript as a scripting language within the script tag in two ways: NB:"If you only specify the script tag without the type or language. Then by default the web browser will assume the scripting language to be JavaScript (since JavaScript is the most commonly used). Example:" The script tag is a paired tag (meaning they appear in twos). This implies that it has an opening tag (e.g ) and a closing tag (e.g ).
 * 1) 
 * 2) 

JavaScript understands and supports HTML tags, this alllows the use of HTML tags in JavaScript without difficulty. To specify a HTML tag in JavaScript, simply place it in quotes (" "). Example:  document.write("Hallo to you my Friend This is Example 1") In the above example, is a HTML tag

Placing Scripts in Pages
Scripts can appear in both the head section and in the body section of a document/ page. The advantage of placing scripts in the head section is that they are executed first every time headers are sent (every time a page is refreshed or loaded). The example below shows two scripts placed in a HTML document, one is placed in the head section and the second script is in the body section (HTML allows both techniques). Example: <!DOCTYPE html>  My first Java Script  document.write("Hallo to you my Friend") document.write("This is Example 1")  document.write("Hallo to you my Friend") document.write("This is Example 1") 

Linking to an external JavaScript file from HTML
You can create and save all your scripts into an external file (with a .js extension), then link to that file from within your HTML document. This is handy if you need to use the same scripts across multiple HTML pages, or a whole website.

To link to an external JavaScript file, you add a src attribute to your HTML script tag and specify the location of the external JavaScript file.

Example:

 or 

The extension .js makes the file to be identified as a JavaScript file.

The code in your .js file should not be different from the code you would normally have placed in between the script tags (as in scripts embedded in HTML files). Though you don't need to specify the script tag again - since it is already on the HTML page that is calling the external file!

Adding Comments
JavaScript supports two types of comments, namely: The comments are important as they serve to explain statements in the script or the purpose of the script. They must be enclosed within the script tags.

Links

 * 1) JS Data Conversion
 * 2) JS Operators
 * 3) JS Input/Output
 * 4) JS Expressions
 * 5) JS Control Structures
 * 6) JS Jump Statements
 * 7) JS Arrays
 * 8) JSFunctions
 * 9) JS Classes and Objects
 * 10) JS Exceptions
 * 11) JS Sample Codes
 * 12) Free JS Projects