Question

Can this be done in JavaScript?

type == 1 ? function1() : function2();
Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top