Coming from a backend-heavy background, I usually lean into objects or maps for flexibility. Been coding for 9+ years, and this one’s served me well.
For something even more scalable, try using a key-value approach:
const actions = {
afshin: () => alert("Hey"),
saeed: () => alert("Hey"),
larry: () => alert("Hey"),
};
(actions[varName] || (() => alert("Default case")))();
This setup moves you away from switch
syntax but keeps the spirit of a javascript switch multiple case structure. It’s especially powerful when each case needs a different action. Plus, it’s neat, extensible, and much easier to maintain as your logic grows.