Skip to content

Code Documentation

ntrappe edited this page Mar 11, 2021 · 10 revisions

CSS Standards

  • 2 spaces
  • IDs/classes should be hyphenated (e.g. #timer-button NOT #timerButton)

JavaScript Standards

  • line width: 100 max
  • 2 spaces
  • variables:
    • let is preferred over var
    • use const for global variables (generally for hard-coded values) and capitalize (e.g. const SEC_PER_MIN = 60)
    • can use single character variables, i, k, j in loops only
  • variables & functions should use camel case (e.g. addTwoNumbers NOT add_two_numbers)
  • variable IDs/classes should be hyphenated (e.g. #timer-button NOT #timerButton)

Code Standards

Note the spacing between characters and placement of curly braces.
Loops:

for (int i = 0; i < len; i++) {
  // do something
}

Functions:

const helloWorld = () => {
  // do something
}

Conditionals:

if (var == 0) {
  // do something
} else {
  // do other thing
}

Code Commenting

/**
 * Add two numbers together
 * @param  {Number} num1 The first number
 * @param  {Number} num2 The second number
 * @return {Number}      The total of the two numbers
 */
function addTwoNumbers(num1, num2) {
  return num1 + num2;
};
Clone this wiki locally