News for hackers. Stuff that matters.
Re:Pipe Operator (|>) For JavaScript by dns_snek on Friday January 20, 2023 @12:04PM (#34456111)
Technically, you should be able to write something uniquely terrible like this ;)

  return (
    <div>
      {(() => {
        const barStuff = bar(stuff);
        return foo(barStuff);
  })()}
    </div>
  )
Re:Pipe Operator (|>) For JavaScript by hajile on Friday January 20, 2023 @12:20PM (#34456368)
They 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)

Re:Pipe Operator (|>) For JavaScript by TheAngush on Friday January 20, 2023 @01:58PM (#34457957)
> 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

Re:Pipe Operator (|>) For JavaScript by brundolf on Friday January 20, 2023 @12:08PM (#34456183)
Yeah, 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