tc39 / proposals

Tracking ECMAScript Proposals
https://tc39.github.io/process-document/
18.12k stars 713 forks source link

Add proposal for object-nullish-coalescing #449

Closed bertyhell closed 1 year ago

bertyhell commented 1 year ago

Proposal for Object property nullish coalescing operator

This proposal shows a new syntax for assigning properties to an object literal but only if the object is not falsy/null or undefined.

Short example:

const myPersonObj = {
    firstName: person.name,
    work?: person.occupation,   // Only set work if person.occupation is truthy, by using the "?:" operator
    street??: person.address    // Only set street is person.address is not null and not undefined, by using the "??:" operator
};
ljharb commented 1 year ago

Proposals can only be added by TC39 members; please see https://github.com/tc39/ecma262/blob/HEAD/CONTRIBUTING.md#new-feature-proposals for more information.

bertyhell commented 1 year ago

ok, i made a discussion topic here: https://es.discourse.group/t/object-nullish-coalescing-operator/1564