JS - Best Practices (Shortcut Notations)

 

Bad :

var lunch = new Array();
lunch[0]='Dosa';
lunch[1]='Roti';
lunch[2]='Rice';
lunch[3]='what the heck is this?';

Good :

let lunch = [
'Dosa',
'Roti',
'Rice',
'what the heck is this?'
];

 

Bad :

if(v){

   var x = v;

} else {

   var x =10;

}

Good :

let x = v || 10;     

 

Bad :

var direction;
if(x > 100){
direction = 1;
} else {
direction = -1;
}

Good :

let direction = (x > 100) ? 1 : -1;

 
 

js best practices