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.

In Bourne shell (and derivatives), "If parameter is unset or null, the expansion of word is substituted.

Otherwise, the value of parameter is substituted":[9] In C#, the null coalescing operator is ?

It is most often used to simplify expressions as follows: 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: instead of the more verbose or The three forms result in the same value being stored into the variable named pageTitle.

Example: Missing values in Apache FreeMarker will normally cause exceptions.

?, the "nullish coalescing operator", which was added to the standard in ECMAScript's 11th edition.

The above Perl code is equivalent to the use of the ternary operator below: This operator's most common usage is to minimize the amount of code used for a simple null check.

Thus they behave differently on values that are false but defined, such as 0 or "" (a zero-length string): PHP 7.0 introduced[15] a null-coalescing operator with the ?

[7] Since R version 4.4.0 the %||% operator is included in base R (previously it was a feature of some packages like rlang).

unwrap_or() serves a similar purpose as the null coalescing operator in other languages.

In Oracle's PL/SQL, the NVL() function provides the same outcome: In SQL Server/Transact-SQL there is the ISNULL function that follows the same prototype pattern: Attention should be taken to not confuse ISNULL with IS NULL – the latter serves to evaluate whether some contents are defined to be NULL or not.

The ANSI SQL-92 standard includes the COALESCE function implemented in Oracle,[18] SQL Server,[19] PostgreSQL,[20] SQLite[21] and MySQL.

It is used to provide a default when unwrapping an optional type: For example, if one wishes to implement some Swift code to give a page a default title if none is present, one may use the following statement: instead of the more verbose