Regarding the ternary (? :) operator in JavaScript, I would like to know how it is evaluated by a typical browser's JavaScript interpreter:
Alternative A:
- Evaluate the first operand.
- If the result of the first operand is true, then evaluate and return the second operand.
- Else, evaluate and return the third operand.
Alternative B:
- All three operands are evaluated.
- If the result of the first operand is true, return the result of the second operand.
- Else, return the result of the third operand.
Alternative C:
Of course, if neither alternative A nor alternative B accurately describe how the ternary operator works, please explain me how it works.
(1)? functionOne(): functionTwo(), if you put a simple alert message on both functions, onlyfunctionOnewill display its message.