DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Taufik Nurrohman
Taufik Nurrohman

Posted on

This Code Snippet Will Make You Think That `switch ... case` Statements Are Obsolete

Before

let b;

switch (a) {
  case '#':
    b = 'one';
    break;
  case '##':
    b = 'two';
    break;
  default:
    b = 'unknown';
}
Enter fullscreen mode Exit fullscreen mode

After

let b = ({
    '#': 'one',
    '##': 'two'
})[a] ?? 'unknown';
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Make Your Github Profile Stand Out

Github is great, but have you considered how to make yours more attractive for potential employers or other visitors? Even non-tech ones like recruiters!

Take a couple of hours and show your best side as a person - and a programmer.