Update coalesce description

This commit is contained in:
Angelos Chalaris
2020-03-05 23:06:58 +02:00
parent 1b5b6d5deb
commit a9c58a0b95

View File

@ -3,14 +3,14 @@ title: coalesce
tags: utility,beginner tags: utility,beginner
--- ---
Returns the first non-null/undefined argument. Returns the first defined, non-null argument.
Use `Array.prototype.find()` to return the first non `null`/`undefined` argument. Use `Array.prototype.find()` and `Array.prototype.includes()` to find the first value that is not equal to `undefined` or `null`.
```js ```js
const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_)); const coalesce = (...args) => args.find(v => ![undefined, null].includes(v));
``` ```
```js ```js
coalesce(null, undefined, '', NaN, 'Waldo'); // "" coalesce(null, undefined, '', NaN, 'Waldo'); // ''
``` ```