Skip to main content

Null-Coalescing Operator

The null-coalescing operator (or more appropriately, nil-coalescing operator) is used as follows:

local value = nillocal result = value ?? "This is the value if 'value' is nil."

It's semantically equal to the following code:

local value = nillocal result = if value == nil then "This is the value if 'value' is nil." else value

As you can see, the null-coalescing operator allows much shorter statements.


This is a lazily-evaluated operator. It will not "choose whatever isn't nil", it'll simply evaluate the second expression if the first expression is nil.