In point 16.1 you state the two block possibilities when it comes to in-line if blocks. These are:
if (test) return false;
if (test) {
return false;
}
Is there any preference to use one or the other?
Personally, I use the first one only at the top of a function, when I have to verify trivial preconditions. (i.e. if (!name) return 'Name is required';.
This style guide allows for both, however I personally strongly prefer the latter, even in the case of early returns, because omitting braces where braces are optional is the cause of many bugs.
I agree that the one-line version makes the most sense when only used for early returns.
Most helpful comment
This style guide allows for both, however I personally strongly prefer the latter, even in the case of early returns, because omitting braces where braces are optional is the cause of many bugs.
I agree that the one-line version makes the most sense when only used for early returns.