Using ternary operator in JavaScript to invoke two functions

前端 未结 2 1418
深忆病人
深忆病人 2020-12-03 10:47

Can this be done in JavaScript?

type == 1 ? function1() : function2();
2条回答
  •  不知归路
    2020-12-03 10:59

    Yes, that's valid code. It will invoke either function1() or function2(), but not both - depending on the value of type.

提交回复
热议问题