# prefer-nullish-coalescing

Prefer nullish coalescing when a nullish value selects a fallback

A conditional that returns a value when it is non-nullish and a fallback otherwise manually implements nullish coalescing.
Instead, you SHOULD use the `??` operator.

- Category: style
- Level: warning
- Fix: automatic
- Scope: module

## Reported

```ds title="main.ds"
function select(value: string | undefined, fallback: string): string {
    return value !== undefined ? value : fallback;
}
```

## Accepted

```ds title="main.ds"
function select(value: string | undefined, fallback: string): string {
    return value ?? fallback;
}
```

## Prior art

- [typescript-eslint · prefer-nullish-coalescing](https://typescript-eslint.io/rules/prefer-nullish-coalescing)

[language/linter/src/rules/style/prefer_nullish_coalescing.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/style/prefer_nullish_coalescing.rs#L8)
