diff --git a/snippets/coalesce.md b/snippets/coalesce.md index 156979331..f57a7ac8b 100644 --- a/snippets/coalesce.md +++ b/snippets/coalesce.md @@ -3,14 +3,14 @@ title: coalesce 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 -const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_)); +const coalesce = (...args) => args.find(v => ![undefined, null].includes(v)); ``` ```js -coalesce(null, undefined, '', NaN, 'Waldo'); // "" -``` \ No newline at end of file +coalesce(null, undefined, '', NaN, 'Waldo'); // '' +```