Statement |
Syntax |
Purpose |
Break |
Break; BreakLabel; |
Exit the innermost loop or switch statement, or exit the label specified statement. |
Case |
CaseExpression: |
Mark a statement in the switch statement |
Continue |
Continue; ContinueLabel; |
Re-start the innermost loop or re-start the cycle specified by label |
Default |
Default: |
Mark the default statement in the switch |
Do/while |
Do Statement While (Expression); |
An alternative form of WHILE LOOP |
Empty |
; |
Do nothing |
For |
For (Initialize;Test;Increment) Statement |
An easy-to-use Loop |
For/in |
For (VariableInObject) Statement |
Traverse the attributes of an object |
Function |
FunctionFuncname([Arg1[...,Argn]) { Statements } |
Declare a function |
If/else |
If (Expression) Statement1 [ElseStatement2] |
Conditional executionCode |
Label |
Identifier:Statement |
ToStatementSpecify a nameIdentifier |
Return |
Return [Expression]; |
Returns the value of an expression by a function or by a function. |
Switch |
Switch (Expression){ Statements } |
Use Case orDefault: multi-branch statements marked by statements |
Throw |
ThrowExpression; |
Throw an exception |
Try |
Try { Statements } Catch (Identifier){ Statements } Finally { Statements } |
Capture an exception |
VaR |
VaRName_1[=Value_1] [,...,Name_n[=Value_n]; |
Declare and initialize a variable |
While |
While (Expression) Statement |
A basic loop statement |
With |
With (Object) Statement |
Extends the current scope chain (not supported) |
Switch language: In JavaScript, the case expression matching the switch language is determined by the = equivalent operator, rather than the = equal operator.
For/in statement: For (variable in object) statement;
Provides a method to traverse object attributes. As follows, for/In cyclically enters all attribute names and their values of an object,
For (VAR prop in my_object ){
Document. Write ("name:" + Prop + "; Value:" + my_object [prop] ");
}
In fact, the for/in loop does not traverse all possible attributes of all objects. Some attributes of an object are marked as read-only, permanent (undeletable), or non-enumerated in the same way. These attributes cannot be enumerated using the for/in loop.
With statement: With statement can greatly reduce the amount of input code, but it runs much slower than the equivalent code that does not use with statement. In addition, function definitions and variable initialization in the with statement may produce unexpected behavior. Therefore, we recommend that you avoid using the with statement.
Null statement: NULL statements do not execute any operations. However, in practice, it is found that null statements are useful when creating a loop with null subjects.