# Alternative (Default value)

This operator is used to provide alternative (or default) values when a particular expression is either null or false.

## LHS is defined

Given a sample.yml file of:

```yaml
a: bridge
```

then

```bash
yq '.a // "hello"' sample.yml
```

will output

```yaml
bridge
```

## LHS is not defined

Given a sample.yml file of:

```yaml
{}
```

then

```bash
yq '.a // "hello"' sample.yml
```

will output

```yaml
hello
```

## LHS is null

Given a sample.yml file of:

```yaml
a: ~
```

then

```bash
yq '.a // "hello"' sample.yml
```

will output

```yaml
hello
```

## LHS is false

Given a sample.yml file of:

```yaml
a: false
```

then

```bash
yq '.a // "hello"' sample.yml
```

will output

```yaml
hello
```

## RHS is an expression

Given a sample.yml file of:

```yaml
a: false
b: cat
```

then

```bash
yq '.a // .b' sample.yml
```

will output

```yaml
cat
```

## Update or create - entity exists

This initialises `a` if it's not present

Given a sample.yml file of:

```yaml
a: 1
```

then

```bash
yq '(.a // (.a = 0)) += 1' sample.yml
```

will output

```yaml
a: 2
```

## Update or create - entity does not exist

This initialises `a` if it's not present

Given a sample.yml file of:

```yaml
b: camel
```

then

```bash
yq '(.a // (.a = 0)) += 1' sample.yml
```

will output

```yaml
b: camel
a: 1
```


---

# 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://mikefarah.gitbook.io/yq/operators/alternative-default-value.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.
