Do expressions
Assign values based on a condition with better readability than ternaries.
| Type | TC39 | CoreJS | Babel | Civet | JS+ |
|---|---|---|---|---|---|
| Syntax | ✅ Stage 0 View | ✅ View | ✅ View | ✅ via Babel |
JS+ TypeScript
const x = 100;const y = 20;
const a = do { if (x > 10) { if (y > 20) { 'big x, big y'; } else { 'big x, small y'; } } else { if (y > 10) { 'small x, big y'; } else { 'small x, small y'; } }};const x = 100;const y = 20;
const a = x > 10 ? y > 20 ? 'big x, big y' : 'big x, small y' : y > 10 ? 'small x, big y' : 'small x, small y';