I remember when I first discovered the concept of pattern matching, I tried to find a way to "hack" the switch statement in js to make it work like pattern matching.
The switch(true) format was the closest I got to it, which I personally don't like compared to a clean if/else or early return.
There's probably some performance differences between if/else and switch (I haven't checked) but it probably end up being what's your preference / what standard code style you want to enforce on your team.
The switch(true) format was the closest I got to it, which I personally don't like compared to a clean if/else or early return.
There's probably some performance differences between if/else and switch (I haven't checked) but it probably end up being what's your preference / what standard code style you want to enforce on your team.