Often times when writing JavaScript I constantly run into blocks like below:
if(shouldDoThis){ doThing(); }
Recently I've seen a different implementation of the same logic which looks like...
shouldDoThis && doThing();
The way the && operator works is it's executed from left to right, only continuing if it hasn't hit a falsy value. So if 'shouldDoThis' is not true, it doesn't continue on to execute the function 'doThing()'.
So in the code below, it would only execute foo() if all 3 required items evaluate as true.
required1 && required2 && required3 && foo()
What are your thoughts on this?