Can this be done in JavaScript?
type == 1 ? function1() : function2();
Yes, this is a valid code. It will call either function1() or function2() , but not both, depending on the value of type .
function1()
function2()
type
It will not call two functions. It will call one of your two functions.