3 ms·
Technically, you should be able to write something uniquely terrible like this ;) return ( <div> {(() => { const barStuff = bar(stuff);
by dns_snek 4y ago
Technically, you should be able to write something uniquely terrible like this ;)
return (
<div>
{(() => {
const barStuff = bar(stuff);
return foo(barStuff);
})()}
</div>
)
- brundolf 4y agoYeah, JS programmers sometimes work around this and similar language gaps by making an inline function and immediately calling it (because that gives you a statement context inside of an expression context, which isn't normally possible). But IMO it's very rarely worth the hit you take to readability
- hajile 4y agoThey should repurpose `do` so that `do {}` (without the `while`) is an expression that you can put statements inside and return the last statement. It would be great if we had expression if..else too (instead of just the tertiary operator)
- TheAngush 4y ago> They should repurpose `do` so that `do {}` (without the `while`) is an expression that you can put statements inside and return the last statement. There's a proposal for precisely that. Unfortunately, only Stage 1 though. https://github.com/tc39/proposal-do-expressions https://github.com/tc39/proposal-do-expressions