Reputation: 6054
I have 3 JS functions a() b() c()
I want to execute all 3 and also check if all 3 return true then I want to call function yeah() or else call function boo()
I can use && but it will short circuit and may not execute all 3 functions if first or second returns false
So
if(a() && b() && c()) { yeah(); } else { boo(); }
wouldn't work!
Can you suggest a better single line code?
Upvotes: 1
Views: 1704
Reputation: 56779
If you want a one-liner, you can also use &
instead of &&
:
if(a() & b() & c()) { yeah(); } else { boo(); }
Or you can do this if you want to know exactly how many functions returned true:
if(a() + b() + c() == 3) { yeah(); } else { boo(); }
Sample: http://jsfiddle.net/DQkpM/1/
Upvotes: 5