3 ms·
cond isn't a trinary operator it is more of a switch statement. Trinary is expressly let x = condition ? truevalue : falsevalue You can do shenanigans by hav
by runevault 2y ago
cond isn't a trinary operator it is more of a switch statement.
Trinary is expressly
let x = condition ? truevalue : falsevalue
You can do shenanigans by having something along the lines of
let x = condition1 ? truevalue1 : (condition2 ? truevalue2 : falsevalue)
- koito17 2y agocond is neither an operator nor a statement, it's an expression. This is a demonstration of a conditional expression handling multiple conditions, which GP wanted. More importantly, pattern matching is not necessary here.
- runevault 2y agoYou misunderstood. They were talking specifically about languages that only have ternary operators as a way to do if-as-expression, and why they prefer languages with either real if-else if-else expressions or full switch/pattern matching as expression.