The null coalescing operator (??) provides a default value when the left operand is null or empty.
value ?? defaultValue
Returns value if it's not null/empty, otherwise returns defaultValue.
- Default values: Provide fallbacks for missing configuration
- Optional parameters: Handle optional function arguments
- User input: Default values when user doesn't provide input
- API responses: Handle missing fields gracefully
You can chain multiple ?? operators:
first ?? second ?? third ?? "final fallback"
oxide main.ox=== Null Coalescing Operator (??) ===
Empty name ?? 'Anonymous' = Anonymous
'John' ?? 'Anonymous' = John
=== Chaining ?? Operators ===
'' ?? '' ?? 'Fallback' = Fallback