- Be careful when returning some values
Ex:
function test(){
return
{
cacheable: true;
}
}
console.log(test()) ;
1 2 3 4 5 6 7 8 9 |
function test(){ return { cacheable: true; } } console.log(test()) ; |
// console.log will return undefined, all of this is happening because the js compiler puts ; (semicolon) after the return statement. Therefore, it’s good practice to have curly braces directly after the return statment
ex: return {
cacheable: true;
}
2. Writing comments
The JS compiler will ignore the white spaces and comments so we can do something like this:
var
// this is the name of the user
firstName,
// this is the surname of the user
surname,
// this should be always more than 0
balance;