So I've thought over this a couple of times, and I may not see the beauty of it, or am missing the benefits, but why couldn't you just put the line of code you want to run either before or after the switch? For example:
You propose:
constmyValue=10;switch(myValue){case10:doThingForValue10();break;case5:doThingForValue5();break;any:// maybe some sort of syntactic sugar to make block run before/after cases are evaluated:console.log(myValue);console.log("run for all cases");}
However, this begs the question of when the any block actually runs. There can be lots of discussion on how we should achieve that, but I think it gets messy especially when you want some code to run before AND after. I think that you can write code with the same functionality in vanilla javascript which would look like this:
constmyValue=10;console.log(myValue);// this would run just the same as it would inside the any blockswitch(myValue){case10:doThingForValue10();break;case5:doThingForValue5();break;}console.log("run for all cases");// not only can we choose if it runs before/after, but we can split code that would be inside the any block to run before AND after
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
So I've thought over this a couple of times, and I may not see the beauty of it, or am missing the benefits, but why couldn't you just put the line of code you want to run either before or after the switch? For example:
You propose:
However, this begs the question of when the
any
block actually runs. There can be lots of discussion on how we should achieve that, but I think it gets messy especially when you want some code to run before AND after. I think that you can write code with the same functionality in vanilla javascript which would look like this: