How is the ternary operator evaluated in JavaScript?

前端 未结 4 1202
猫巷女王i
猫巷女王i 2021-02-19 06:19

Regarding the ternary (? :) operator in JavaScript, I would like to know how it is evaluated by a typical browser\'s JavaScript interpreter:

Alternative A:<

4条回答
  •  眼角桃花
    2021-02-19 06:49

    The "alternative A":

    (1)? functionOne(): functionTwo()
    

    If you put a simple alert message on both functions, only functionOne will display its message.

    function functionOne(){ 
       alert("one");
    }
    function functionTwo(){ 
       alert("two");
    }
    

提交回复
热议问题