All the JavaScript statement used in this tutorial are listed here under the following headings:
The IF ... ELSE STATEMENT
The conditional statement, IF, is one that executes if a specific condition is true. You many also execute an additional statement if the conditional statement is false by using the ELSE. The format of the condition IF is:
The condition can be any JavaScript statement that can be evaluated as either TRUE or FALSE. The statement(s) to be executed can be any Javascript statements including nested IF statements. If you want to use more than one statement after either an IF or ELSE then you must use curly brackets, { }, to enclose the statements. As a general rule, you should always use curly brackets with any IF..ELSE statements even if there is only one executable statement.
An example of the IF..ELSE statement is:
The SWITCH STATEMENT
The conditional statement, SWITCH, evaluates an expression and attempts to match it with one of the case labels. If a match is found then the statement within the case is executed.
NOTE: If the JavaScript Reserve Word, break, which is optional is not present, then the code immediately following will be executed, i.e. the next case label. If the break is present, then the statement following the switch will be executed. A normal following statement is default:, which is the statement to be executed if none of the cases match the expression.
An example of the SWITCH is :
The FOR, WHILE, and DO WHILE Looping statements continue to execute until a specific condition is true.
The FOR STATEMENT
The WHILE STATEMENT
The WHILE statement is only executed if the conditional statement is true.
The DO WHILE STATEMENT
The DO WHILE executes the initial statement once before the conditional statement is checked and continues executing until the conditional statement is false.
The CONTINUE STATEMENT
The continue statement can be used in a WHILE, FOR, and LABEL statement. In a WHILE or FOR loop the CONTINUE stops the current iteration and continues with the next iteration. In a WHILE loop, it jumps back to the condition statement. In a FOR loop, it jumps to the increment-expression statement.
In a LABEL statement, the CONTINUE must be followed the the label.
In the above I am using if ((j%2)==0); continue checkonj; to say, " if j equals zero, go back to checking on j".
The BREAK STATEMENT
In a WHILE or FOR statement, BREAK terminates the current loop and transfers control to the statement following the terminated loop. In a label statement, the BREAK causes the label statement to terminate and the statement after the label statement is executed.
Objects can be manipulated in several ways.
NEW
Use the NEW operator to create a new instance of a user defined objects or a built-in objects such as: Array, Boolean, Date, Function, Image, Number, Object, Option, RegExp, or String. The format for using new is:
THIS
The THIS operator to refer to the current object. Normally, it will refer to the calling object in a method. The format is:
FOR...IN
The for...in statement iterates a specified variable over all the properties of an object. For each distinct property, JavaScript executes the specified statements. A for...in statement looks as follows:
"
return result
}
For an object car with properties make and model, result would be:
car.make = Ford
car.model = Mustang
WITH
The with statement establishes the default object for a set of statements. Within the set of statements, any property references that do not specify an object are assumed to be for the default object. A with statement looks as follows:
Comments are a way for you to note within your JavaScript what you are trying to accomplish. Example of this are:
|
|