Switch expressions

Switch statements are a nice way to go through a set of cases. We have ternary expressions that can be used in place of if statements. It would be great to have an expression for switch too.

For example, the match expression in Rust, Scala, etc.

const k = 5;
const times = match (k) {
    case 1 => "once"
    case 3 => "thrice"
    case 5 => "five times"
}

See GitHub - tc39/proposal-pattern-matching: Pattern matching syntax for ECMAScript

1 Like

Thanks, exactly what I was looking for. Hope it gets to stage 3.