DEV Community

Discussion on: Which would you prefer and why?

Collapse
 
simov profile image
simo

I had to say why do I prefer it and why, right?

  1. Well, that's the most elegant way to do it, without creating an object just to return the value in the end.
  2. It's better than using switch, no fall-through footgun here.
  3. It's obviously more elegant than if-else-return.
  4. Implicitly returns a value - essential for functional programming (that can be achieved with the object approach too).

While it might not be the prettiest code to see - it's what we currently have in the language, also it's pretty straightforward to understand.