Logical assignment for default assignments

A proposal for using the logical assignments ||= and ??= in default assignment in function arguments and destructuring.

I've made a repo here: https://github.com/jun-sheaf/proposal-logical-default-assignment.

Looking for feedback (and a champion :trophy:)

5 Likes

Bump (can we bump here :face_with_hand_over_mouth:)

1 Like

Have you considered including 'logical and' &&= for completeness?

2 Likes

What would be the use case?

1 Like

I've far more often wanted ?? behavior than strictly "not undefined" on function arguments, and it's not possible to migrate to default parameters without causing breakage in many existing libraries.

I was just thinking about proposing this and found that it already had been proposed. I completely agree with claudiameadows. It is often the case that I want default parameters to replace both undefined and null. That is my primary use case. I can imagine scenarios where other logical assignments might be desired.

I was originally optimistic that extractors could be the answer, but logical assignment seems a very natural and low hanging opportunity.

1 Like