Hacker News new | past | comments | ask | show | jobs | submit login

No need to ‘return’ when you throw an error, but your approach is valid IMO: if structure / readability is that important, refactor the switch to it’s own method with only if checks in it. Hard to make that simpler and more readable.



If you don't have a 'return' there's nothing to say that some time later some junior developer would not modify throw to be something else or forget that throw does not return.


This will prevent the JR dev from making that mistake: https://eslint.org/docs/rules/no-fallthrough


That's what tests are for.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: