DEV Community

Discussion on: Opinionated use of JavaScript Switch-Case

Collapse
 
sirseanofloxley profile image
Sean Allin Newell

Wat. I am so intrigued

const someFlag = true;
const name = 'bob'; // or tom

switch (name) {
  case 'bob':
    return someFlag ? 20 : 10;
  case 'tom':
    return 5;
  default:
    return -1;
}
Enter fullscreen mode Exit fullscreen mode

This seems clearer to me, but i can see the flexibility of your way.

Collapse
 
rfornal profile image
bob.ts

I agree that yours might be clearer with a smaller example, but when using something with dozens of variables, it's clear and the flexibility is really nice.