-
Notifications
You must be signed in to change notification settings - Fork 42
Coding Conventions
Dinith edited this page Mar 11, 2020
·
4 revisions
- Variable names
lowerCamelCase
- Constant names
UPPER_SNAKE_CASE
- This includes environment variables
- No magic numbers
- Always use constants where applicable
- If you find yourself changing the same value in multiple places it should probably be a constant
- JSON key names
-
lower_snake_case
for constant values (e.g. data returned by API) -
lowerCamelCase
if using them in a similar way toconst
andlet
-
- Function names
- Should be short and descriptive (indicative of what function does)
- Don't add 'function' on the end of the function name
- e.g.
getData()
, notgetDataFunction()
- Function declarations
- Named arrow functions where possible
- e.g.
const func = (x, y) => { ... }
- e.g.
- Otherwise use
function
keyword assigned to aconst
- e.g.
const func = function (x, y) { ... }
- This is most similar to the arrow function so makes it uniform/easy to read
- e.g.
- Named arrow functions where possible
- Avoid anonymous functions where possible (function names are useful for error tracing and indicating what it does)
- Exception to this is for callback functions
- Put opening curly brackets on the same line for
if
,for
andwhile
- e.g.
if (...) {
- NOT
if (...) </br>{
- e.g.
- Entry point of program at top
- Called methods below caller method
- Catching errors (err)
- Always use curly braces, even if one statement follows the if/for/arrow function
- DON'T USE
var
- Always use
const
if the value won't change - Otherwise use
let