Recently I came across this little bit of JS logic:
close(focusAfter) {
if (! this.open) return;
this.open = false;
focusAfter && focusAfter.focus();
},
The truthy-ness check of focusAfter is clearly used as an inline conditional to make sure a valid object/element exists before calling .focus() on it.
It seems to me that the equivalent logic could be clarified when rewritten as:
if (focusAfter) focusAfter.focus();
My question is: is there any "not-immediately-obvious" advantage to the inline boolean-check-then-execution shown in the original example versus explicitly writing an inline if statement to "wrap" the executed logic (in this case, focusAfter.focus())?