12.5 If statement

2010-05-23

IfStatement :
if ( Expression ) Statement else Statement
if ( Expression ) Statement

Whenever it is unclear (ambiguous) to which if an else belongs, it should always be associated with the nearest possible if that would otherwise have no else associated to it.

Code: (Meta Ecma)
function evaluate(if ( Expression ) Statement(1) else Statement(2)) {
var exprRef = evaluate(Expression);
if (ToBoolean(GetValue(exprRef))) {
return evaluate(Statement(1));
}
return evaluate(Statement(2));
}


Code: (Meta Ecma)
function evaluate(if ( Expression ) Statement) {
var exprRef = evaluate(Expression);
if (ToBoolean(GetValue(exprRef))) {
return evaluate(Statement(1));
}
return Completion('normal', undefined, undefined);
}