Re:Show HN: Ferrum.js – Rust features in JS: traits and adva...
by nicoburns on Wednesday July 03, 2019 @09:08AM
(#20343956)
Ternary operator don't nest very nicely though (they do nest , but it's not very readable). IMO a bigger difference is Rust's match and blocks also being expressions. These have no alternatives in JavaScript.
[ Parent
| on HN ]
Re:Show HN: Ferrum.js – Rust features in JS: traits and adva...
by bfrydl on Wednesday July 03, 2019 @09:25AM
(#20344061)
Nesting multiple branches of ternary operators doesn't work well but if it's a sort of “if elseif elseif else” situation I think this looks pretty nice:
x > 0 ? 'positive' :
x < 0 ? 'negative' :
'zero'
Re:Show HN: Ferrum.js – Rust features in JS: traits and adva...
by nicoburns on Wednesday July 03, 2019 @09:32AM
(#20344110)
But not nearly as nice as:
match x {
0 => 'zero',
x if x > 0 => 'positive',
x if x < 0 => 'negative',
}