14 lines
285 B
Markdown
14 lines
285 B
Markdown
### coalesce
|
|
|
|
Returns the first non-null/undefined argument.
|
|
|
|
Use `Array.find()` to return the first non `null`/`undefined` argument.
|
|
|
|
```js
|
|
const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_));
|
|
```
|
|
|
|
```js
|
|
coalesce(null, undefined, '', NaN, 'Waldo'); // ""
|
|
```
|