Specifications

var
var variableName;
var anotherVariableName = InitialValue;
This keyword is used to declare and optionally initialize variables. If just the variableName is
given, the variable is created, but it has no value, that is, its value is undefined. If an InitialValue
is given, the variable is created and assigned this InitialValue. Variables declared within functions
are local to the function in which they are declared. Variables declared outside of functions and
classes are global.
Example:
var i;
var count = 22;
var str = "string";
Control statements
The flow-of-control in JavaScript programs is controlled by control statements, for example: if,
switch, for and while. JavaScript also supports exceptions with try and catch.
This topic discusses control statements in alphabetical order: break, case, catch, continue, default,
do, else, for, if, finally, label, return, Switch, throw, try, try...catch, try...finally, while, with.
break
label:
for ( var i = 0; i < limit; i++ ) {
if ( condition ) {
break label;
}
}
switch ( expression ) {
case 1:
Statements1;
break;
default:
DefaultStatements;
break;
}
This keyword is used in, for loops, do loops, while loops and Switch statements. When a break
statement is encountered in a loop, control is passed to the statement following the end of the
inner-most loop that contains the break statement; unless the break statement is followed by
the name of a label, in which case control passes to the statement governed by the label.
A break statement is usually placed at the end of each case in a Switch statement to prevent the
interpreter "falling through" to the next case. When the interpreter encounters a break statement,
it passes control to the statement that follows the inner-most enclosing Switch statement. If
every case has a corresponding break, then at most one case's statements will be executed.
If the break statement is followed by a label name (see label) then when the break is encountered,
control will pass to the statement marked with that label; this is useful, for example, for breaking
out of deeply nested loops.
Example:
red:
for ( x = 0; x < object.width; x++ ) {
for ( y = 0; y < object.height; y++ ) {
if ( color[x][y] == 0xFF0000 ) {
400
Enfocus Switch 10