1000% agree. While this method of utilizing a switch _could_ result in less overall LOC due to not needing curly braces for an if statement declaration, it is inherently less extensible as sequential if/else statements. This is something I'd look at in a codebase, and after 10 seconds go "huh okay, cool I guess", and move on with my day very slightly annoyed that I had to spend those 10 seconds processing the deviation in standards haha
Discovered this recently too, it works really well for some instances! I haven't had much experience in Rust, but I heard the match statement kind of works like this. It would be great to have it in JS too!
This is not as performative as an if-else chain because every time it is executed, the interpreter will execute the pointless comparison "true==true", so besides the comparisons executed on each case, an extra unnecessary comparison will be executed
breaks principle of least surprise, therefore i would not recommend this.
ah you must be fun to work with 😂
have you forgotten to take your meds again?
@@apidas when production is down and i need to fix a bug fast i don't want to run into "fun" code.
1000% agree. While this method of utilizing a switch _could_ result in less overall LOC due to not needing curly braces for an if statement declaration, it is inherently less extensible as sequential if/else statements.
This is something I'd look at in a codebase, and after 10 seconds go "huh okay, cool I guess", and move on with my day very slightly annoyed that I had to spend those 10 seconds processing the deviation in standards haha
@@FunctionGermanyyeah, keep your for loop and require statements
C# has much more flexible switch statements, since I regularly use both C# and JS, this trick goes a ways into making JS switches as flexible as in C#
Discovered this recently too, it works really well for some instances! I haven't had much experience in Rust, but I heard the match statement kind of works like this. It would be great to have it in JS too!
I had no idea you can do that!
Just use an if statement dude 😂
😂 that’s what I thought
It might be a little neater than if then else, but not by much
Very cool
Smelly code
neat
Or you can just do if else
This is not as performative as an if-else chain because every time it is executed, the interpreter will execute the pointless comparison "true==true", so besides the comparisons executed on each case, an extra unnecessary comparison will be executed