DEV Community

Discussion on: Switch statements in javascript – How to refactor?

Collapse
 
jwhenry3 profile image
Justin Henry

I like to use the object map pattern to avoid switch statements, as it does allow adding keys and values to increase the flexibility of the condition, and allows direct access to map values rather than relying on logic branches (which could cause complexity issues for grading platforms). Another thought is parallel arrays, but that requires a little more care when constructing as you will need to know what each index means in the parallel arrays. being able to access map[key].property to avoid branches are really nice.

Collapse
 
ajayv1 profile image
Ajay Kumar Verma

Yes Justin, I also do the same and thought of sharing this point through the article. I am new to dev.to, Its really nice to share and get the comments.