Stop using if/switch, use objects instead
To say the role of if/ switch in any programming language would be an understatement. even some of the well-known js libraries use if/switch in some form or other. if you poke around in jQuery you will find it checks multiple if conditions to returning the value.
so what’s wrong with well-known established if/switch
- Straight up Dry
Dry, in sense it’s boring and requires a lot of boilerplate code, this may work for 2 to 3 cases but what happens when you have a lot of conditions to check or wish to change the existing condition. Well, it wouldn’t be hard to think that might get cumbersome, which something as a programmer we all try to avoid. Remember,
“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” — Martin Fowler


2. Objects are the king
In javascript objects are the king we use them all the time even when we do not realize we are. all methods are exposed to use with the help of objects in javascript, so why not maintain that js flow in our codebase. recently I was writing a react component that expects a prop based on that it runs a function. it was a piece of cake to think in terms of objects & had my “ah” moment with it. if you look down below this looks well manage and neat. it cannot getter much simpler in terms of readability and for any future changes.

3. Objects are FUN
Objects work in a rather predictable way we all know how to access their properties or method attach to them (dot notation). With objects, things just work with ease. if you wish to access its own properties no problem, wish to tie a function to a specific object you got that covered too. keeping a set template to write a code pays off well from get-o. it wouldn’t be a stretch that would be one less thing to worry about
Conclusion: These are my few reasons that makes me love JS, even more, sure other programming languages have them too but not in a way JS handles object