Difference between revisions of "ProgClub standard JavaScript format"
From ProgClub
(Work, work...) |
m (White space...) |
||
Line 42: | Line 42: | ||
if ( true ) { | if ( true ) { | ||
− | + | ||
foo(); | foo(); | ||
Revision as of 00:05, 12 April 2016
OK, so if there's such a thing as the ProgClub standard JavaScript format I'd better explain what that is... this page remains a work in progress.
Always use curly brackets even when not required:
if ( true ) { return foo(); } // not: if ( true ) return foo();
All on one line if only one short statement:
if ( true ) { return false; } // not: if ( true ) { return false; }
Multiple lines if an if-block is followed by else/else-if:
if ( true ) { return false; } else { return true; } // not: if ( true ) { return false; } else { return true; }
Multiple lines if more than one statement:
if ( true ) { foo(); bar(); } // not: if ( true ) { foo(); bar(); }
Open curly bracket on same line, close curly bracket on new line:
function test() { return true; }
Always use a semicolon if you can!
Try to keep line-length less than 78 characters (not a hard rule).