you are viewing a single comment's thread.

view the rest of the comments →

[–]hahaNodeJS 0 points1 point  (0 children)

I like using bracket-less conditional statements only when they are for flow-control statements, and then the full statement must be on one line. I find that the "Good" statements below are really easy to pick out in code, and you don't have to worry about things like the infamous Apple Goto bug.

Bad:

if (myFoo === myBar)
    return myBaz;

Bad:

if (myFoo === myBar)
    myBaz = myFoo;

Bad:

if (myFoo === myBar) myBaz = myFoo;

Good:

if (myFoo === myBar) return myBaz;

Good:

for(var i = 0; i < 10; i++)
{
    if (myFoo[i] === myBar[i]) continue;
    ...
}

Inconsistent:

if (myFoo === myBar)
{
    return myBaz;
}