# Coalesce

The coalesce `??` operator can be used to provide default values when the given path does not exist, or causes some error.

The operator will pass through to the secondary value if:

* A given map key doesn't exist
* A given array index doesn't exist
* The given expressions returns `null`
* An operation is performed on an invalid type

## Examples

### Check if a property or index exists

```
if ($someArray[10] ?? false) {
    // exists
} else {
    // does not exist
}

if ($someMap.foo ?? false) {
    // exists
} else {
    // does not exist
}
```

### Default values when something doesn't exist

```
foo.bar.baz ?? "my sensible default"
```

### Chaining

The coalesce operator can be chained, with items towards the left taking prescedence.

```
foo ?? bar ?? baz ?? false
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://daseldocs.tomwright.me/syntax/coalesce.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
