Difference between revisions of "ProgClub standard JavaScript format"
From ProgClub
(WIP...) |
(Work, work...) |
||
Line 1: | Line 1: | ||
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. | 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 statement: | ||
+ | |||
+ | if ( true ) { return false; } | ||
+ | |||
+ | // not: | ||
+ | |||
+ | if ( true ) { | ||
+ | |||
+ | return false; | ||
+ | |||
+ | } | ||
+ | |||
+ | Multiple lines if and if-block is followed by else/else-if: | ||
+ | |||
+ | if ( true ) { | ||
+ | |||
+ | return false; | ||
+ | |||
+ | } | ||
+ | else { | ||
+ | |||
+ | return true; | ||
+ | |||
+ | } | ||
+ | |||
+ | // not: | ||
+ | |||
+ | if ( true ) { return false; } | ||
+ | else { return true; } |
Revision as of 23:59, 11 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 statement:
if ( true ) { return false; }
// not:
if ( true ) {
return false; }
Multiple lines if and if-block is followed by else/else-if:
if ( true ) { return false;
} else {
return true;
} // not: if ( true ) { return false; } else { return true; }