philnash@programming.dev to JavaScript@programming.dev • 11 months agoStop nesting ternaries in JavaScriptexternal-linkmessage-square17 fedilinkarrow-up121
arrow-up121external-linkStop nesting ternaries in JavaScriptphilnash@programming.dev to JavaScript@programming.dev • 11 months agomessage-square17 Commentsfedilink
minus-squareJakenVeina@lemm.eehexbear1·edit-211 months agoNah, I meant switch, as that's what it's called in C#-land. See above. That proposal for matching looks interesting, but not quite the same, no. linkfedilink
minus-squarespartanatreyu@programming.devhexbear4·edit-211 months agoAre you sure? Your C# example: var output = input switch { null => "Null", 0 => "Zero", > 0 => "Positive", _ => "Negative" }; JS proposal for match: const output = match input { when null: "Null"; when 0: "Zero"; if input > 0: "Positive"; default: "Negative"; } linkfedilink
minus-squareJakenVeina@lemm.eehexbear1·11 months agoAha, yeah, I see it now. Looking forward to it. linkfedilink
Nah, I meant switch, as that's what it's called in C#-land. See above.
That proposal for matching looks interesting, but not quite the same, no.
Are you sure?
Your C# example:
var output = input switch { null => "Null", 0 => "Zero", > 0 => "Positive", _ => "Negative" };
JS proposal for match:
const output = match input { when null: "Null"; when 0: "Zero"; if input > 0: "Positive"; default: "Negative"; }
Aha, yeah, I see it now. Looking forward to it.