News for hackers. Stuff that matters.
Re:Using the switch(true) pattern in JavaScript by planb on Monday April 12, 2021 @11:14AM (#26780291)
That’s not how throw works. And that’s exactly why the switch(true) pattern should not be used: novice users not fully knowledgeable about every specification of a language should not fail to understand such a basic piece of code.

There’s not even a line difference to using if statements correctly (as others in the comments have demonstrated) The one thing an if statement does is checking if something is ‚true‘. I don’t understand why anyone would use a ‚switch‘ here apart from showing how clever they are.

There are no comments on this comment yet.