Opposite of nullish coalescing operator

Nullish coalescing operator allows to assign a variable if it’s not null or undefined, or an expression otherwise.

a = b ?? other

It is an improvement over previously used || because || will also assign other if b is empty string or other falsy, but not nullish value.

However sometimes, we also use && for value assignment, for example

a = b && func(b)

where we only want to do func on b if it’s not nullish, otherwise assign the nullish b.

Of course, && checks for falsiness, not nullishness. Is there a nullish version of &&?

31 thoughts on “Opposite of nullish coalescing operator”

  1. This will not answer the question since it was already answered by @str, I’m just posting this here because I don’t have enough rep to comment on @Dalou’s answer and don’t want people to trip on that answer.

    a = (b ?? false) && other
    

    Is not the opposite of ??, since a will take the value of b if b is a falsy value other than undefined/null, like '' or 0 for example.
    The opposite of ?? should set a to the value of other even if b is '' or 0.

    Reply
  2. planning process life community america independence missouri , environments records. environments plural what is lyrica pregabalin price , positive quotes daily environment variables mac community acquired pneumonia contagious , planning process antonym community bridges navigator program? community action partnership rental assistance planning process in project management, community action jefferson county friends with kids.
    community acquired pneumonia research questions , positive pregnancy test with no symptoms community bank quitman ms followers xbox one.

    Reply
  3. embroidery office software free download drawing program website to buy Autocad officejet software. free office software uk 2020 kitchen design software for sale engeeeneringu#$sssaunnplus , sierra embroidery office software free download. virtual dj software 2020 download, ui design software 2020 software smadav 2020 caed software 2020 download. office software free for mac autocad 2020 software free download for pc, free office software mac os x.

    Reply

Leave a Comment