DEV Community

Discussion on: Write More Robust JavaScript: 7 Best Practices

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

Why type is not a switch I don't know, although I have never heard that this is a conversation. Nor that using prototype when a class keyword is more appropriate.

Collapse
 
jsmanifest profile image
jsmanifest • Edited

A switch here would be just fine since it just returns the result. However in a lot of situations when i'm considering switch cases I don't have to return the value evaluated from the case block which ultimately I'd become forced to put in a break which unnecessarily adds more lines than needed. In those situations it looks much nicer to just write if/else conditions while keeping the code short.