3 ms·
I prefer this: if(foo()) bar(); No {} necessary if it's just a single command.
by chime 16y ago
I prefer this:
if(foo()) bar();
No {} necessary if it's just a single command.
- mshafrir 16y agoI prefer to always use {} for readability and consistency's sake, regardless of line count. Also reduces human error.
- chime 16y agoMe too. But if the goal was to shorten "if(foo()) { bar(); }, then I could just leave the {} braces out instead of making it "foo() && bar()".
- TrevorBurnham 16y agoYes, I admit that I added the curly braces unnecessarily. However, jsLint will throw a fit if you omit them, so there's an argument to be made that always putting your conditionals in curly braces is a best practice. Certainly, both styles are common in JavaScript, and they'll come out of the minifier the same way in the end.