Hacker News new | ask | show | jobs
by smt88 2269 days ago
You're seeing it for the first time because it's a bad pattern. It's confusing to a reader who is expecting a typical switch use-case, and it has no performance benefit over a series of if statements.

I don't know about V8, but a lot of compilers would have a harder time optimizing this because of the strange structure. For mature compilers and naive (i.e. not-yet-profiled) projects, it's better to write what you mean and let the compiler optimize it.

1 comments

Go does this too, and it's actually OK once you get used to it. The switch statement is still saying "it's one of these things"