Null Coalescing

Noun · Development

Definitions

  1. An operator (`??` in C#, PHP, JavaScript, and others) that evaluates to its left-hand operand if that operand is non-null (or non-nullish in JS), and to its right-hand operand otherwise. Unlike the logical OR (`||`), it does not treat falsy values like `0` or `""` as absent.

    In plain English: A shorthand that says 'use this value if it's not empty/missing, otherwise fall back to a default.'

    Example: "We replaced the ternary null checks with null coalescing — `user.name ?? 'Anonymous'` reads so much cleaner."

Related Terms