DEV Community

loading...

Discussion on: 5 ways to refactor if/else statements in JS functions

Collapse
sylwiavargas profile image
Sylwia Vargas Author

Hi @afpaiva ! Thank you for your question!
In comparison with if/else statements, switch statements are a bit faster with small number of cases and get incrementally faster with new conditions. Readability, it seems that devs prefer to read if/else for two conditions and then switches for more.
There's this great table from O'reilly:
performance table comparing switches, if/else and table lookups

Talking about performance in C is both beyond my expertise and comfort level, sadly!