DEV Community

Discussion on: Why I prefer objects over switch statements

Collapse
 
oscherler profile image
Olivier “Ölbaum” Scherler

I agree that when a switch statement is used to perform a mapping (which is not always the case), then it’s usually better to replace it with an actual mapping. But we should also keep readability in mind. Your last switch statement immediately shows what it’s doing. The object approach is less immediate.

(Also, pattern matching is not an ES6 proposal, it’s an ancestral FP principle that’s proposed for addition to ES6.)