How is the ternary operator evaluated in JavaScript? -
regarding ternary (? :
) operator in javascript, know how evaluated typical browser's javascript interpreter:
alternative a:
- evaluate first operand.
- if result of first operand true, evaluate , return second operand.
- else, evaluate , return third operand.
alternative b:
- all 3 operands evaluated.
- if result of first operand true, return result of second operand.
- else, return result of third operand.
alternative c:
of course, if neither alternative nor alternative b accurately describe how ternary operator works, please explain me how works.
the "alternative a":
(1)? functionone(): functiontwo()
if put simple alert message on both functions, functionone display message.
function functionone(){ alert("one"); } function functiontwo(){ alert("two"); }
Comments
Post a Comment