1const dogSwitch = (breed) => ({
2 "border": "Border Collies are good boys and girls.",
3 "pitbull": "Pit Bulls are good boys and girls.",
4 "german": "German Shepherds are good boys and girls."
5})[breed]
6dogSwitch("border") // "Border Collies are good boys and girls."
1function getDrink (type) {
2 var drinks = {
3 'coke': function () {
4 return 'Coke';
5 },
6 'pepsi': function () {
7 return 'Pepsi';
8 },
9 'lemonade': function () {
10 return 'Lemonade';
11 },
12 'default': function () {
13 return 'Default item';
14 }
15 };
16 return (drinks[type] || drinks['default'])();
17}
1function getSnack (type) {
2 var snack;
3 function isDrink () {
4 return snack = 'Drink';
5 }
6 function isFood () {
7 return snack = 'Food';
8 }
9 var snacks = {
10 'coke': isDrink,
11 'pepsi': isDrink,
12 'cookies': isFood,
13 'crisps': isFood,
14 };
15 return snacks[type]();
16}
17
18var snack = getSnack('coke');
19console.log(snack); // 'Drink'