Using ternary operator in JavaScript to invoke two functions

Can this be done in JavaScript?

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

Answers:

Answer

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

Answer

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

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.