This Code Snippet Will Make You Think That `switch ... case` Statements Are Obsolete
Taufik Nurrohman
Posted on December 29, 2019
Before
let b;
switch (a) {
case '#':
b = 'one';
break;
case '##':
b = 'two';
break;
default:
b = 'unknown';
}
After
let b = ({
'#': 'one',
'##': 'two'
})[a] ?? 'unknown';
💖 💪 🙅 🚩
Taufik Nurrohman
Posted on December 29, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.