Javascript Tutorials and Reference Guides

Introduction

JavaScript is a scripting language created by Netscape in the late 1990s. Originally it was called LiveScript but, given the popularity of the Java programming language at the time, Netscape renamed it JavaScript hoping to capitalize on the name. In reality there are very few similarities between the two, and while JavaScript became popular the name has done little more than confuse.

Netscape History - The browser that gave birth to JavaScript & popularized the Web.

Operators

Like most languages JavaScript has operators for comparing, and modifying data. Many of JavaScripts operators are C-Like. Similar to C parentheses can be used to group operations, though without parentheses JavaScript uses an order of operations similar to that of C, which derives from operator precedence in mathematics. JavaScript also uses short circuit evaluation in comparisons. If the first part of a JavaScript statement would make certain that the whole statement would be either true or false then the remaining portion of the statement is skipped. The following are some of JavaScript operators.

= The Assignment operator assigns the value on the right to the variable on the right.

= The Assignment operator assigns the value on the right to the variable on the right.

+= Increments the variable on the left by the value on the right and assigns the result to the variable on the left.

-= Decrements the variable on the left by the value on the right and assigns the result to the variable on the left.

*= Multiplies the variable on the left by the value on the right and assigns the result to the variable on the left.

/= Divides the variable on the left by the value on the right and assigns the result to the variable on the left.

%= Performs a modulus operation on the variable on the left by the value on the right and assigns the result to the variable on the left.

Comparison Operators

== Compares the Value on the left to the value on the right.

% (Modulus) Divides the first operand by the second and returns the remainder.

++ (Increment) increases the value of a variable by 1.

-- (Decrement) decreases the value of a variable by 1.

- (Unary Negation) negates the value of a variable. For instance a variable with a value of 1 would become negative 1 (-1).

Bitwise Operators

Bitwise operators act on bits in memory, and treat variables as though they were binary numbers. This allows bitwise operators, like those from Assembly language, to be implemented in JavaScript programs.

Statements

Outside of using the comma operator, all JavaScript statements are separated by semi-colons, which is a common feature of c-like languages. This remains true even if multiple statements appear on the same line, or within an HTML event like the onClick handler. At the same time, because statements are delimited by semicolons, a single statement can span multiple lines which is often useful for making complex statements easier to understand and properly document.

Core Objects

There are a few core objects, and data types which are commonly used in JavaScript scripting. JavaScript being object oriented all data types act as objects and complex datatypes, like strings, inherit properties from simple objects like arrays. Complex objects can inherit the properties of multiple simple types as well.

Array - Is an object for storing Arrays, and Associative arrays dynamically

Boolean - Implements a Boolean data type, which has only 2 possible states

Date - Is an object for storing a date, and contains many functions for representing dates in different formats.

Number - Is an object used to treat a number differently for different operations, like decimal, real, etc.

Document

Document properties are used to access the HTML DOM. In inter-application scripting some of these may be re-implemented to access properties of another type of document. One of the most common uses for JavaScript is manipulating DOM objects within hypertext documents. AJAX, which utilizes JavaScript to implement advance interactivity, uses the document object.

Anchor - An object for manipulating anchor properties and detecting the coordinates of anchor text.

Applet - An Object for interacting with Applets, such as Java or Flash applets.

Window

JavaScript has a separate set of objects for dealing with Windows. At first this may seem odd since there is already a document object. In fact a Window contains a Document object. The Window object deals with functionality related to or between Windows, as well as the history, and window properties like location, and size. Frames act as separate windows and have essentially the same objects.

History - An object for moving through and displaying information about a Window's History log.

Form

The Form object deals with the properties of HTML forms. This can be used to update forms as information is entered, or to validate what information has been entered as well as offer extra options depending what kind of data has been entered.

Hidden - An attribute that can make a form invisible unless it is needed.