loading...

re: Opinionated use of JavaScript Switch-Case VIEW POST

FULL DISCUSSION
 

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;
}

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

 

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.

Code of Conduct Report abuse