Skip to main content

Nulls (null)

A null is used to refer to the intentional absence of a value.

While it can be used as a separate type directly, null most commonly used to make an existing type explicitly nullable:

interface Math extends HybridObject<{}> {
a: number | null
}

The NullType is a singleton structure in Nitro. To return null to JS:

func getNull() -> NullType {
return .null
}

Optionals vs null

In the same way that JavaScript distinguishes between an optional type/undefined and null, Nitro also has two separate concepts for the two.

If you simply want to make an existing type optional, use Optionals instead.