Story of Kelly Johnson
So, try to keep your code and system structure simple.
No PIE & framework magic in the code unless you can justify their need. Because, they always requires you to add more classes and add complexity to your code.
if (var1 === null || var1 === undefined || var1 === '') {
console.log("VARIABLE NOT FOUND!");
} else {
console.log(var1);
}
console.log( var1 || "VARIABLE NOT FOUND!" );
function sayHello(name) {
console.log('Hello', name);
}
can be replaced with arrow function
const sayHello = name => console.log("Hello", name);
different scoping methodology.
const list = [2, 5, 7, 2, 6, 2, 3, 5];
for (let i = 0; i < list.length; i++) {
console.log(list[i]);
}
list.forEach(number => console.log(number));
function volume(l, w, h) {
if (w === undefined)
w = 1;
if (h === undefined)
h = 1;
return l * w * h;
}
const volume = ( l, w = 1, h = 1) => l * w * h
const person = {
first: 'Wes',
last: 'Bos',
country: 'Canada',
city: 'Hamilton',
twitter: '@wesbos'
};
const first = person.first;
const last = person.last;
vs
let { first, last } = person;
const odd = [1, 2, 3];
const nums = [4, 5, 6].concat(odd);
vs
const nums = [4, 5, 6, ...odd];
function weekday1(dayOfWeek){
switch(dayOfWeek){
case 1: return "Monday";
case 2: return "Tuesday";
case 3: return "Wednesday";
case 4: return "Thursday";
case 5: return "Friday";
case 6: return "Saturday";
case 7: return "Sunday";
default:
throw new Error("dayOfWeek - in range 1..7");
}
}
function weekday2(dayOfWeek){
if((dayOfWeek < 1) || (dayOfWeek > 7))
throw new Error("dayOfWeek must be in range 1..7");
let weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
return weekdays[dayOfWeek-1];
}