79088914

Date: 2024-10-15 08:00:20
Score: 4
Natty:
Report link

There are drafts and proposals, which will do exactly what you wanted to do. It's called Safe Assignment Operator (?=).

The syntax would be:

const t ?= someFunc() || somethingElse;

or

const [error, t] ?= someFunct();

See: dev.to - Effortless Error Handling in JavaScript: How the Safe Assignment Operator Simplifies Your Code or Medium - JavaScript Safe Assignment Operator (?=): A Complete Guide

And there is a similar package you can already use: https://www.npmjs.com/package/with-error

Follow their progress. I am also looking forward to it :)

Reasons:
  • Blacklisted phrase (2): I am also looking
  • Probably link only (1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Doleance