js alternative to switch code example
Example 1: js switch case
switch(expression) {
case x:
break;
case y:
break;
default:
}
Example 2: ultimate course replace switch with object
function getDrink (type) {
var drinks = {
'coke': 'Coke',
'pepsi': 'Pepsi',
'lemonade': 'Lemonade',
'default': 'Default item'
};
return 'The drink I chose was ' + (drinks[type] || drinks['default']);
}
var drink = getDrink('coke');
console.log(drink);
Example 3: typescript inline switch
{(() => {
switch (header) {
case "Name": return entry.name;
case "Type": return entry.type;
default: return entry.name;
}
})()}