5 ms·
Pattern matching (and expression based assignment, of which idk if there’s a proposal for or not) are two things that would really drive a ton of value.
by halfmatthalfcat 2y ago
Pattern matching (and expression based assignment, of which idk if there’s a proposal for or not) are two things that would really drive a ton of value.
- CharlieDigital 2y agoIt's going to end up looking a lot like C# [0][1]; these two/three (JS/TS, C#) languages have been converging for a while now. Now just waiting for C# to get official first party discriminated unions! [0] https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/patterns https://learn.microsoft.com/en-us/dotnet/csharp/language-ref... [1] https://timdeschryver.dev/blog/pattern-matching-examples-in-csharp https://timdeschryver.dev/blog/pattern-matching-examples-in-...
- adabyron 2y agoJust an FYI for those unaware TS & C# are both creations of Anders Hejlsberg & his colleagues at Microsoft. Both are some of my favorite languages as well. We would all benefit if JS was more like C# in my opinion.
- recursive 2y agoAssignment is already an expression, no? console.log(x = "hello");
- 65 2y agoNow try it with a constant: console.log(const x = "hello"); Doesn't work.
- recursive 2y agoThat's a declaration. That would be cool. Doesn't currently work with let or var either.
- 65 2y agoI think this is basically assigning values to the window object, similar to updating values in any object. e.g. const a = { b: 1 } console.log(a.b = 2); // logs 2
- recursive 2y agoOnly if you haven't already declared the variable. e.g. let x; console.log(x = 'hello'); My point is that the `x = 'hello'` part is an assignment, and an expression, and has the exact same semantics regardless of whether you use that expression as a statement. So, assignments would seem to be expressions.