Fallback operation
Learn how to provide fallback values.
The fallback operation provides a default value when something is missing, such as optional attributes or parameters.
To specify a default value, place the ?? operator between the expression you want to check and the fallback value:
user's name ?? "Anonymous"
In the above example, the expression returns either the user's name or "Anonymous" if the user's name is missing.
For a more natural language feel, you can write:
user's name or else "Anonymous"
You can also chain multiple fallback values together to return the first non-absent value:
user's name or else user's nickname or else "Anonymous"
In this case, the expression checks the user's name first, then the nickname, and finally returns the fallback if both are missing.