12 Statements

2010-05-23

Statement :
Block
VariableStatement
EmptyStatement
ExpressionStatement
IfStatement
IterationStatement
ContinueStatement
BreakStatement
ReturnStatement
WidthStatement
LabelledStatement
SwitchStatement
ThrowStatement
TryStatement
DebuggerStatement

A Statement is a line of code that does not return anything. In fact, unlike expressions, it must always be at the start of a line (after automatic semi-colon insertion), with the possible exception of Whitespace or a label preceeding it (forming a LabeledStatement).

Ecmascript does not have the FunctionStatement production. All function declarations are expressions (they always return something). So this means named functions (which are parsed ahead), are still expressions. The specification notes that certain implementations do support FunctionDeclarations, but their specific behaviour is so irratic that their use is incompatible and therefore discouraged.

Any statement can be preceeded by one or more labels and become a LabeledStatement. All the labels in the out-most LabeledStatement are called "the current label set". A LabeledStatement simply means the introduction of another label into a label set. The label set of an IterationStatement or SwitchStatement initially contains the single element "empty". Any other statement starts out with an empty label set.

All statements return a value of type Completion (8.9). This Completion type has three properties, type, value and target. I find it a little confusing that the specification doesn't at least repeat this fact in section 12, because it just returns the triple in all the Statement evaluations. So the returned value is an object which tells the invokers of the evaluation how the evaluation ended.