[syntax] Inverse null coalescing operator

I think for parity with the other nullish/optional operators, the expression would need to evaluate to undefined rather than null for the lhs-nullish branch.

A couple benefits to having an operator for this (in addition to optional pipeline chaining, not instead of):

  • operator would work with RHS template strings / arithmetic without needing an extra function
  • it should be possible to chain more than one of these "type guards" together
    and do something with more than one value.
  • no need to create a wrapper function or hope partial application is implemented
    to call a function with multiple arguments

I think I posted a near duplicate of this yesterday with some additional hypothetical examples
(as ?::, but token doesn't matter other than needing to have a ? in it somewhere)

x ?:: y ?:: `${x} ${y}` //this would be ok if evaluated l-r right?
(a ?:: a + 2) ?? 0  // in combination with nullish coalescing
1 Like