Regarding the ternary (? :
) operator in JavaScript, I would like to know how it is evaluated by a typical browser\'s JavaScript interpreter:
Alternative A:<
According to the specification it works like in Alternative A:
The production
ConditionalExpression : LogicalORExpression ? AssignmentExpression : AssignmentExpression
is evaluated as follows:
- Let
lref
be the result of evaluatingLogicalORExpression
.- If
ToBoolean(GetValue(lref))
istrue
, then
- Let
trueRef
be the result of evaluating the firstAssignmentExpression
.- Return
GetValue(trueRef)
.- Else
- Let
falseRef
be the result of evaluating the secondAssignmentExpression
.- Return
GetValue(falseRef)
.