Skip to content

Latest commit

 

History

History
131 lines (111 loc) · 2.42 KB

File metadata and controls

131 lines (111 loc) · 2.42 KB

Brief Style Guide

This is a very brief BloomingLeaf Javascript style guide.

General guidelines

Add semicolons to the end of each line
// do this
console.log('Hello'); 

// not this
console.log('Hello')  
Add spaces between tokens
// do this
for (var i = 0; i < 5; i++) {
    console.log('Hello');
}

// not this
for(var i=0;i<5;i++){
    console.log('Hello');
}

// do this
var i = 0;

// not this
var i=0;
Variable and function names should be camel case
// do this
var myNum = 18;

// not this
var my_num = 18;

Declaring Variables

Currently, the source code consists of var declarations rather than the more modern counterparts, let and const.
var a = 15;
let b = 15;
const c = 15;

If statements

Add opening and closing curly braces even though the if-block would only be one line long.
// do this
if (1 === 5) {
    console.log('Hello');
}

// not this
if (1 === 5) console.log('Hello');

// not this either
if (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 this
if (1 === 5) {
    console.log('Hello');
} else {
    console.log('Goodbye');
}
    
// not this
if (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 this
for (var i = 0; i < 4; i++) {
    console.log('Hello');
}
    
// not this
for (var i = 0; i < 4; i++) console.log('Hello');

// not this either
for (var i = 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}
 */
function sum(a, b) {
    return a + 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}
 */
function sum(a, b) {
    return a + b;
}