Using ternary operator in JavaScript to invoke two

2019-01-11 18:04发布

问题:

Can this be done in JavaScript?

type == 1 ? function1() : function2();

回答1:

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



回答2:

It won't invoke two functions. It will invoke one of your two functions.