Specifications

If the return statement is followed by an expression (optExpression) the value of the expression
is returned to the caller.
Example:
function inRange( v, min, max )
{
if ( v >= min && v <= max ) {
return true;
}
else {
return false;
}
}
switch
switch( expression ) {
case Value :
Statements;
break;
default :
DefaultStatements;
break;
}
A switch statement provides a multi-way branch. The expression is evaluated once, then each
case is checked in order to find one with a Value that matches the value of the expression. If a
match is made, the statements of the matching case are executed, after which control passes to
the statement following the switch block. If no matching case is found and there is a default
case, the DefaultStatements are executed, after which control passes to the statement following
the switch block. If there is no matching case and no default, no statements within the switch
block are executed and control passes to the statement following the switch block.
Note that if a default is used it must be come after all the cases; this is because once default is
encountered it is treated as a matching case regardless of what follows.
Every case and the default (if used) should have a break as their last statement. If break is not
present, control will "drop through" to the following statements, which is not usually the desired
behavior.
The expression may be any arbitrary JavaScript expression that evaluates to an object that can
be strictly compared. For example, an expression that evaluates to a Boolean, Date, Number or
String value.
Example:
switch( expr ) {
case 1:
doActionOne();
break;
case "two":
doActionTwo();
break;
case 3:
doActionThree();
case 4:
doActionFour();
break;
default:
doDefaultAction();
break;
}
In the example, if expr has the value 1, the doActionOne() function will be called. But if expr has
the value 3, both doActionThree() and doActionFour() will be called because case 3 does not have
405
Enfocus Switch 10