if

The if statement is a very simple way to provide an alternate path for execution. If the condition is found to be true, the statement or statements are executed. The syntax and example given below illustrate this very nicely.

syntax:

if (condition) {

statements

}

EXAMPLE

var stuff = 1;

if (stuff == true) {

document.write("The Stuff is True");

}

The above example first declares a variable, called 'stuff'. The value entered is 'one', which is the boolean true. Since the condition of the if statement has been set to true, the if statement will execute (if it were set to false, the if statement would not execute). In this case, the statement instructs the browser to display the caption 'The Stuff is True'.