r/ProgrammerAnimemes • • May 20 '23

Ternary operator

Post image
1.5k Upvotes

41 comments sorted by

View all comments

Show parent comment

1

u/bucket3432 Jun 05 '23

Rust, is that? Yeah, it would be nice if other languages supported something like that... which apparently PHP has since version 8?!

$a = 2;
return match ($a) {
  1 => "one",
  2 => "two",
  3 => "three",
  default => "other",
};

On the JavaScript side, there's a Stage 1 proposal for a similar construct. I don't see that moving anytime soon.

2

u/Diapolo10 Jun 05 '23

Rust indeed! I'm quite fond of it, personally, even though I wouldn't say I'm particularly good at using it yet.