14.6 The if
Statement
Syntax
The lookahead-restriction [lookahead ≠
else
] resolves the classic "dangling else" problem in the usual way. That is, when the choice of associated if
is otherwise ambiguous, the else
is associated with the nearest (innermost) of the candidate if
s14.6.1 Static Semantics: Early Errors
-
It is a Syntax Error if
IsLabelledFunction (the firstStatement ) istrue . -
It is a Syntax Error if
IsLabelledFunction (the secondStatement ) istrue .
-
It is a Syntax Error if
IsLabelledFunction (Statement ) istrue .
It is only necessary to apply this rule if the extension specified in
14.6.2 Runtime Semantics: Evaluation
- Let exprRef be ?
Evaluation ofExpression . - Let exprValue be
ToBoolean (?GetValue (exprRef)). - If exprValue is
true , then- Let stmtCompletion be
Completion (Evaluation of the firstStatement ).
- Let stmtCompletion be
- Else,
- Let stmtCompletion be
Completion (Evaluation of the secondStatement ).
- Let stmtCompletion be
- Return ?
UpdateEmpty (stmtCompletion,undefined ).
- Let exprRef be ?
Evaluation ofExpression . - Let exprValue be
ToBoolean (?GetValue (exprRef)). - If exprValue is
false , then- Return
undefined .
- Return
- Else,
- Let stmtCompletion be
Completion (Evaluation ofStatement ). - Return ?
UpdateEmpty (stmtCompletion,undefined ).
- Let stmtCompletion be