How is the ternary operator evaluated in JavaScript? -


regarding ternary (? :) operator in javascript, know how evaluated typical browser's javascript interpreter:

alternative a:

  1. evaluate first operand.
  2. if result of first operand true, evaluate , return second operand.
  3. else, evaluate , return third operand.

alternative b:

  1. all 3 operands evaluated.
  2. if result of first operand true, return result of second operand.
  3. 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

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -