Skip to content

Null coalescing operator

While its behavior differs between implementations, the null coalescing operator generally returns the result of its left-most operand if it exists and is not null, and otherwise returns the right-most operand.

Core Idea

The null coalescing operator is a binary operator that forms a basic conditional expression: it returns its left-hand operand if that operand exists and is not null, and otherwise returns its right-hand operand. Exact behavior differs between implementations, but this is the general rule. It is most commonly written as x ?? y, though the notation varies across programming languages.

The operator appears in several languages, including C# since version 2.0, Dart since version 1.12.0, PHP since version 7.0.0, Perl since version 5.10 (as "logical defined-or"), PowerShell since 7.0.0, and Swift (as the "nil-coalescing operator"). Its main use is to supply a default value for cases where a more specific value is not available. Some languages offer the same outcome through functions rather than an operator; in SQL, for example, Oracle's NVL() and Transact-SQL's ISNULL() take a possibly null value and a fallback. ISNULL should not be confused with the IS NULL predicate, which only tests whether a value is null.

Like the binary Elvis operator, usually written x ?: y, the null coalescing operator short-circuits: it does not evaluate the second operand if that value is not needed, which matters when evaluating it would have side effects. Null coalescing tests definedness rather than truth: Perl's // differs from its older || on values that are false but defined, so 0 // 1 yields 0 where 0 || 1 yields 1.

How would you explain it like I'm…

Use This, Or That

Imagine you ask, "Is there a cookie in the jar?" If there is, you get the cookie. If the jar is empty, you get an apple instead. The null coalescing operator is a little computer rule that does exactly that: use the first thing if it's there, otherwise use the backup.

The Backup-Value Trick

In programming, sometimes a box that should hold a value is empty, which programmers call 'null'. The null coalescing operator, often written as two question marks (x ?? y), says: if x has a real value, use it; if x is empty, use y instead. This makes it easy to give a default value when a more specific one isn't available. It's also lazy in a smart way: if x is fine, the computer doesn't even bother working out y.

Default-If-Null Operator

The null coalescing operator is a binary operator found in several programming languages, commonly written x ?? y, though the exact spelling varies. It returns the left operand if it exists and is not null; otherwise it returns the right operand. This is a compact way to supply a default, for example name ?? "Guest". It is short-circuiting: the right-hand side is only evaluated if it is actually needed, which matters when evaluating it has side effects like printing or changing data. It's related to the Elvis operator (x ?: y), and details of its behaviour differ between languages.

 

The null coalescing operator is a binary operator forming a compact conditional expression in languages including C#, Dart, PHP, Perl (as logical defined-or), PowerShell, and Swift (as nil-coalescing). Generally, it evaluates to its left operand when that operand exists and is non-null, and otherwise to its right operand. The canonical spelling is x ?? y, though syntax varies. Its main use is supplying a default value when a more specific value is absent. Like the binary Elvis operator (x ?: y), it short-circuits: the right operand is evaluated only when needed, which is significant when that evaluation has side effects. Details differ between implementations, so the general rule is a family resemblance rather than one exact semantics. In SQL contexts, a function like ISNULL should not be confused with the IS NULL predicate, which only tests whether a value is NULL.

Structural Signature

Sig role-phrases:

  • Defining carrier — This is an unusual choice of symbol, given that ?: is typically used for the Elvis operator, not null coalescing, but it was inspired by Groovy (programming language) where null is considered false.
  • Constitutive relation — The difference between ISNULL and COALESCE is that the type returned by ISNULL is the type of the leftmost value while COALESCE returns the type of the first non-null value.
  • Operating condition — This behavior allows a default value to be defined for cases where a more specific value is not available.
  • Recognition evidence — In Bourne shell (and derivatives), "If parameter is unset or null, the expansion of word is substituted.
  • Admissible variation — For example, if one wishes to implement some C# code to give a page a default title if none is present, one may use the following statement.
  • Characteristic consequence — The three forms result in the same value being stored into the variable named pageTitle .
  • Failure boundary — suppliedTitle is referenced only once when using the ?? operator, and twice in the other two code examples.

What It Is Not

  • Not the whole field of computer science. The node requires the specific identity stated by While its behavior differs between implementations, the null coalescing operator generally returns the result of its left-most operand if it exists and is not null, and otherwise returns the right-most operand.
  • Not an over-broad reading. Once a non-null value is assigned to number, or it reaches the final value (which may or may not be null), the expression is completed.
  • Not an over-broad reading. For example, the following will return the default title if either the page object is null or page is not null but its Title property is.
  • Not an over-broad reading. However, both missing and null values can be handled, with an optional default value.
  • Not automatically Elvis Operator. Retrieval proximity does not establish equivalence; the two identities must be compared by carrier, operation, and failure boundary.

Scope of Application

Null coalescing operator applies literally inside computer science wherever the source-defined carrier and relation can be established. Its documented habitats include:

  • Rust. While there's no null in Rust, tagged unions are used for the same purpose.
  • Rust. Alternatively, unwrap_or_else() can be used to use the result of a function as a default value.
  • Examples by languagesBourne-like shells. The operator can also be used multiple times in the same expression.
  • Examples by languagesBourne-like shells. If, for example, a variable should be changed to another value if its value evaluates to null, since C# 8.0 the ??= null coalescing assignment operator can be used.
  • Examples by languagesBourne-like shells. In combination with the null-conditional operator ?. or the null-conditional element access operator ?[] the null coalescing operator can be used to provide a default value if an object or an object's member is null.
  • JavaScript. In earlier versions, it could be used via a Babel plugin, and in TypeScript.

Outside computer science, the name should be retained only when these same operational conditions survive; otherwise the comparison belongs to the broader parent Representation or should be marked as analogy.

Clarity

A clear use of Null coalescing operator names the carrier, the operative relation, and the conditions under which the source treats the identity as present. The minimal definition is While its behavior differs between implementations, the null coalescing operator generally returns the result of its left-most operand if it exists and is not null, and otherwise returns the right-most operand. The strongest recognition evidence is: In Bourne shell (and derivatives), "If parameter is unset or null, the expansion of word is substituted. A report should distinguish that evidence from a proxy, consequence, or common implementation. It should also state the qualification Once a non-null value is assigned to number, or it reaches the final value (which may or may not be null), the expression is completed. so that a reader can reproduce the classification rather than infer it from topical resemblance.

Manages Complexity

Null coalescing operator compresses multiple programming-language details into a stable diagnostic relation. The source shows both the central mechanism—the difference between ISNULL and COALESCE is that the type returned by ISNULL is the type of the leftmost value while COALESCE returns the type of the first non-null value.—and the practical consequence—the three forms result in the same value being stored into the variable named pageTitle . This compression makes cases comparable while leaving parameters, conventions, exceptions, and evidential quality explicit. It is lossy by design: local history and implementation details may be omitted only when they do not alter the defining relation.

Abstract Reasoning

  1. Type the carrier. Identify the programming-language entities to which the claim applies.
  2. State the relation. Use the source-grounded identity: While its behavior differs between implementations, the null coalescing operator generally returns the result of its left-most operand if it exists and is not null, and otherwise returns the right-most operand.
  3. Check operation and conditions. This behavior allows a default value to be defined for cases where a more specific value is not available.
  4. Demand recognition evidence. In Bourne shell (and derivatives), "If parameter is unset or null, the expansion of word is substituted.
  5. Test variation. Change an implementation or setting while preserving for example, if one wishes to implement some C# code to give a page a default title if none is present, one may use the following statement.
  6. Run the collapse test. Remove the defining operation; if the label still seems equally apt, only a topic or correlate was retained.
  7. Reduce cautiously. When the specialist conditions cannot be carried, route the residual comparison to Representation.

Knowledge Transfer

Within the home domain. Knowledge about Null coalescing operator transfers literally when a new case preserves the same carrier type, relation, and recognition test. While there's no null in Rust, tagged unions are used for the same purpose. Alternatively, unwrap_or_else() can be used to use the result of a function as a default value.

Beyond the home domain. No canonical parent is asserted for Null coalescing operator. An outside case receives the specialist name only when the same typed roles and rejection conditions can be filled literally; otherwise the comparison remains an analogy pending later graph densification.

Examples

Canonical

For example, if one wishes to implement some C# code to give a page a default title if none is present, one may use the following statement. This case is canonical because it supplies a concrete carrier and lets the defining relation be checked rather than merely named.

Mapped back: carrier → the entities in the documented case; operation → While its behavior differs between implementations, the null coalescing operator generally returns the result of its left-most operand if it exists and is not null, and otherwise returns the right-most operand; recognition evidence → In Bourne shell (and derivatives), "If parameter is unset or null, the expansion of word is substituted

Applied / In Practice

If, for example, a variable should be changed to another value if its value evaluates to null, since C# 8.0 the ??= null coalescing assignment operator can be used. The applied case shows how the identity is used under a second setting or qualification while keeping the same operative relation.

Mapped back: changed setting → Examples by languagesBourne-like shells; invariant → While its behavior differs between implementations, the null coalescing operator generally returns the result of its left-most operand if it exists and is not null, and otherwise returns the right-most operand; boundary → the case exits the class when once a non-null value is assigned to number, or it reaches the final value (which may or may not be null), the expression is completed

Structural Tensions

T1 — Stable identity versus admissible variation. Once a non-null value is assigned to number, or it reaches the final value (which may or may not be null), the expression is completed. The tension matters because emphasizing only one side either dissolves the identity or overstates what the evidence and domain conventions warrant.

Diagnostic: Which changes preserve the defining relation, and which replace it?

T2 — Recognition versus proxy. For example, the following will return the default title if either the page object is null or page is not null but its Title property is. The tension matters because emphasizing only one side either dissolves the identity or overstates what the evidence and domain conventions warrant.

Diagnostic: Does the cited evidence establish the identity or only a correlated sign?

T3 — Definition versus implementation. However, both missing and null values can be handled, with an optional default value. The tension matters because emphasizing only one side either dissolves the identity or overstates what the evidence and domain conventions warrant.

Diagnostic: Is the observed implementation constitutive, optional, or merely common?

T4 — Scope versus overextension. It evaluates its left-hand operand and, if the result value is not "nullish" ( null or undefined ), takes that value as its result; otherwise, it evaluates the right-hand operand and takes the resulting value as its result. The tension matters because emphasizing only one side either dissolves the identity or overstates what the evidence and domain conventions warrant.

Diagnostic: Can every claimed application fill the same typed roles without metaphor?

T5 — Transfer versus domain accent. This is an unusual choice of symbol, given that ?: is typically used for the Elvis operator, not null coalescing, but it was inspired by Groovy (programming language) where null is considered false. The tension matters because emphasizing only one side either dissolves the identity or overstates what the evidence and domain conventions warrant.

Diagnostic: Does the receiving case instantiate Null coalescing operator literally, co-instantiate Representation, or only resemble it?

T6 — Autonomy versus reduction. The difference between ISNULL and COALESCE is that the type returned by ISNULL is the type of the leftmost value while COALESCE returns the type of the first non-null value. The tension matters because emphasizing only one side either dissolves the identity or overstates what the evidence and domain conventions warrant.

Diagnostic: What does Null coalescing operator distinguish that the broader parent Representation leaves together?

Structural–Framed Character

Null coalescing operator is structural-leaning. Its structural side is the repeatable organization summarized by While its behavior differs between implementations, the null coalescing operator generally returns the result of its left-most operand if it exists and is not null, and otherwise returns the right-most operand. Its framed side is the programming-language vocabulary that fixes the carrier, evidence, exceptions, and admissible transformations.

Evaluative weight: the identity can be stated descriptively even when applications carry practical stakes. Human-practice dependence: the source-grounded carrier determines whether the relation exists independently or is constituted by a practice. Institutional origin: disciplinary conventions stabilize the name and test. Vocabulary portability: This behavior allows a default value to be defined for cases where a more specific value is not available. Import versus recognition: literal transfer requires the same mechanism; shape alone is analogy.

Its portable skeleton is Representation. Its character: a recurring specialist identity whose thin organization can be abstracted, while its operational meaning remains domain-bound.

Structural Core vs. Domain Accent

What is skeletal. While its behavior differs between implementations, the null coalescing operator generally returns the result of its left-most operand if it exists and is not null, and otherwise returns the right-most operand. The stable skeleton is the typed relation expressed in that definition and the entry's recognition and collapse tests. The source identifies these operative conditions: This is an unusual choice of symbol, given that ?: is typically used for the Elvis operator, not null coalescing, but it was inspired by Groovy (programming language) where null is considered false. The difference between ISNULL and COALESCE is that the type returned by ISNULL is the type of the leftmost value while COALESCE returns the type of the first non-null value. It further constrains recognition and variation through: This behavior allows a default value to be defined for cases where a more specific value is not available. In Bourne shell (and derivatives), "If parameter is unset or null, the expansion of word is substituted.

What is domain-bound. mathematics logic statistics supplies the operative entities, technical vocabulary, warrants, and exceptions that make Null coalescing operator literal. Its documented scope includes the condition that While there's no null in Rust, tagged unions are used for the same purpose. Another bounded application condition is that Alternatively, unwraporelse() can be used to use the result of a function as a default value. These are not decorative examples; they determine which carrier and evidence can fill the abstraction's roles.

Why no parent is asserted. Removing those specialist details does not currently yield one live catalog node that is a necessary genus for every instance. The entry is therefore approved as unparented rather than attached by topical resemblance. Its collapse evidence remains specific—For example, if one wishes to implement some C# code to give a page a default title if none is present, one may use the following statement.—and future graph densification may discover a defensible relation only if it preserves that boundary.

This entry under conditions is a kind of Logical Operation.

  • Approved unparented node. No current live node supplies a defensible necessary genus or structural prerequisite for Null coalescing operator. The reviewed identity is: While its behavior differs between implementations, the null coalescing operator generally returns the result of its left-most operand if it exists and is not null, and otherwise returns the right-most operand. The accelerated suggestion was declined because topical or lexical similarity does not establish hierarchy; the node is admitted without a parent pending later graph densification.
  • Related reasoning operations. Evidence, representation, comparison, classification, transformation, or evaluation may participate in particular cases, but participation does not make any one of them a necessary parent of every instance.

Relationships to Other Abstractions

Local relationship map for Null coalescing operatorParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Null coalescingoperatorDOMAINDomain-specific abstraction: Logical Operation — is a kind of, conditionalLogicalOperationDOMAIN

Current abstraction Null coalescing operator Domain-specific

Parents (1) — outgoing typed relations

  • Null coalescing operator is a kind of, conditional Logical Operation Domain-specific

    Supported as a formal selection operation over nullable program values, with language-specific semantics.

    Condition / exception Supported as a formal selection operation over nullable program values, with language-specific semantics.

Hierarchy path (1) — routes to 1 parentless root

Neighborhood in Abstraction Space

Null coalescing operator sits in a sparse region of the domain-specific corpus (75th percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Formal Notation & Symbol Conventions (5 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-11-14

Not to Be Confused With

  • Representation. The parent omits the specialist differentia. Tell: Can the case establish While its behavior differs between implementations, the null coalescing operator generally returns the result of its left-most operand if it exists and is not null, and otherwise returns the right-most operand?
  • Elvis Operator. Elvis Operator is a recurring identity in computer science defined by: Binary operator in computer programming. Tell: Which entry's carrier, operation, and failure condition are satisfied?
  • Common operator notation. A formal-expression grammar in which operands and prefix, infix, postfix, grouping, and separator operators are parsed through precedence and associativity rules. Tell: Which entry's carrier, operation, and failure condition are satisfied?
  • Branch Table. A constant-time multiway dispatch structure that maps a validated selector through a dense table of code addresses or branch instructions to one of several control-flow targets. Tell: Which entry's carrier, operation, and failure condition are satisfied?
  • A measurement, proxy, or consequence. Those may provide evidence without being the identity. Tell: Would Null coalescing operator remain present if the detector or downstream effect changed?
  • A metaphorical analogue. A similar shape outside computer science lacks the specialist mechanism. Tell: Do the native roles transfer literally, or only the parent Representation?

References

  • Frozen Wikipedia discovery revision: https://en.wikipedia.org/wiki/Null_coalescing_operator (revision 1355306421).