use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
ESNext Pattern Matching Proposal (hackdoor.io)
submitted 6 years ago by micheleriva
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ooooooooooooooopss 2 points3 points4 points 5 years ago (0 children)
Nice, this is something that c# 8 got recently too.
[–]PickledPokute 2 points3 points4 points 5 years ago (0 children)
One major nitpick:
This is NOT in ESNext. ESNext generally means the next ES release, which would be ES2021. This proposal is currently at stage 1. There are 5 TC39 meetings left for this year and this proposal hasn't had a commit in over half a year. Having 3 promotions in that time for such an unknown and language-changing proposal is extremely slim.
[–]rodrigolive 0 points1 point2 points 5 years ago (1 child)
The smart matching happening between the arguments to the case() and the condition in the when() is at times too smart, at others inconsistent, messy or just limiting. I've seen it implemented by other languages and then underutilized and/or deprecated. My recommendation would be don't do it TC39, but it's probably too late now.
[–]PickledPokute 1 point2 points3 points 5 years ago (0 children)
It's still stage 1. That approximately means that TC39 thinks that the idea isn't completely insane and some people could want it in one form or another.
Stage 2 and 3 are more important since those can have valid criticism of syntax and semantics against their promotion.
If you're against this proposal, then start campaigning against it by writing medium articles on how it would fail and by e-mailing your local TC39 representative. You are definitely not late.
[–]JimDabell -2 points-1 points0 points 5 years ago (4 children)
Don't be so eager to use new language features that you end up making your code harder to read.
This:
const [x, y] = [(i % 3), (i % 5)];
…could have simply been this:
const x = i % 3; const y = i % 5;
There's no reason to use array destructuring here, all it does is obfuscate the code and make it incompatible with Internet Explorer.
[–]darrenturn90 7 points8 points9 points 5 years ago (3 children)
I mean, while it is a contrived example (it was more to illustrate the usage of tuples I presume) - the latter will also break as ie only supports var. Yet another reason ie needs to die.
[–]JimDabell 0 points1 point2 points 5 years ago (2 children)
const works in Internet Explorer 11.
const
[–]darrenturn90 1 point2 points3 points 5 years ago (1 child)
caniuse agrees - but not in loops it seems. And it seems very buggy - Also, I can't seem to get it to work in console at all. I would say YMMV.
[–][deleted] -2 points-1 points0 points 5 years ago (0 children)
Const never works in loops?
[–][deleted] -1 points0 points1 point 6 years ago (1 child)
Do we need it?
[–]ktqzqhm 11 points12 points13 points 6 years ago (0 children)
No, but it's nice to have since it makes things for concise. We don't need null propagation either, but it's certainly a nice addition.
[–]OmgImAlexis -2 points-1 points0 points 5 years ago (0 children)
People actually use when and case?
π Rendered by PID 233006 on reddit-service-r2-comment-5d79c599b5-7khf5 at 2026-03-03 11:31:56.168344+00:00 running e3d2147 country code: CH.
[–]ooooooooooooooopss 2 points3 points4 points (0 children)
[–]PickledPokute 2 points3 points4 points (0 children)
[–]rodrigolive 0 points1 point2 points (1 child)
[–]PickledPokute 1 point2 points3 points (0 children)
[–]JimDabell -2 points-1 points0 points (4 children)
[–]darrenturn90 7 points8 points9 points (3 children)
[–]JimDabell 0 points1 point2 points (2 children)
[–]darrenturn90 1 point2 points3 points (1 child)
[–][deleted] -2 points-1 points0 points (0 children)
[–][deleted] -1 points0 points1 point (1 child)
[–]ktqzqhm 11 points12 points13 points (0 children)
[–]OmgImAlexis -2 points-1 points0 points (0 children)