You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a very brief BloomingLeaf Javascript style guide.
General guidelines
Add semicolons to the end of each line
// do thisconsole.log('Hello');// not thisconsole.log('Hello')
Add spaces between tokens
// do thisfor(vari=0;i<5;i++){console.log('Hello');}// not thisfor(vari=0;i<5;i++){console.log('Hello');}// do thisvari=0;// not thisvari=0;
Variable and function names should be camel case
// do thisvarmyNum=18;// not thisvarmy_num=18;
Declaring Variables
Currently, the source code consists of var declarations rather than the more modern counterparts, let and const.
vara=15;letb=15;constc=15;
If statements
Add opening and closing curly braces even though the if-block would only be one line long.
// do thisif(1===5){console.log('Hello');}// not thisif(1===5)console.log('Hello');// not this eitherif(1===5)console.log('Hello');
The else and else if keywords should be on the same line as the closing curly brace from the previous if or else if block.
// do thisif(1===5){console.log('Hello');}else{console.log('Goodbye');}// not thisif(1===5){console.log('Hello');}else{console.log('Goodbye');}
For loops
Curly braces are required even if the for loop body is only one line long.
// do thisfor(vari=0;i<4;i++){console.log('Hello');}// not thisfor(vari=0;i<4;i++)console.log('Hello');// not this eitherfor(vari=0;i<4;i++)console.log('Hello');
Documenting functions
When defining functions, documentation should be written in the following format.
// do this/** * Returns the sum of a and b * * @param {Number} a * @param {Number} b * @returns {Numner} */functionsum(a,b){returna+b;}
There should be a new line between the function description and the parameter description. If each parameter must be explained in more detail, please do the following.
/** * Returns the sum of a and b * * @param {Number} a * The first operand * @param {Number} b * The second operand * @returns {Numner} */functionsum(a,b){returna+b;}