-
Notifications
You must be signed in to change notification settings - Fork 0
Javascript: Guidelines
Oscar Fabiano edited this page Jul 6, 2021
·
1 revision
This is a guide to recommendations for javascript programming. It's based on code review and real mistakes made by the team over time, so it is absolutely necessary to read and follow these recommendations.
- Will you add something to the page? Create a component
- Split your work into different files and folders
- If you notice that your code has many lines, methods and variables. It's time to start refactoring, creating smaller components and working with emit
- Before creating anything, check that there is no component. We already have components for a date, list, simple tables and upload fields
- Before merging into the master branch, check if your component if is showing errors on the console (F12)
Wrong way:
if(variable === 1)
if(variable === 0)
if(variable === true)
if(variable === false)
Right way:
if(variable)
if(!variable)
Wrong way:
var flag = true
if(flag)
var x = false
if(x)
var i = 0
if(i > 0)
Right way:
var isEnabled = true
if(isEnabled)
var countSales = 0
if(countSales > 0)
Wrong way:
variable = 1
variable = 0
Right way:
variable = true
variable = false
Wrong way:
if(condition) doSomething()
Right way:
if(condition){
doSomething()
}
Wrong way:
if(condition) variable = 'something'
else variable = 'something else'
Right way:
variable = condition ? 'something' : 'something else'
Wrong way:
for(var i = 0; i < data.lenght; i++){
// data[i]
}
Right way:
data.forEach(item => {
// item
});