philnash@programming.dev to JavaScript@programming.dev • 1 year agoStop nesting ternaries in JavaScriptexternal-linkmessage-square17 fedilinkarrow-up121
arrow-up121external-linkStop nesting ternaries in JavaScriptphilnash@programming.dev to JavaScript@programming.dev • 1 year agomessage-square17 Commentsfedilink
minus-squareJakenVeina@lemm.eehexbear1·edit-21 year 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-21 year 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·1 year 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.