Returns the first defined, non-null argument.

Use Array.prototype.find() and Array.prototype.includes() to find the first value that is not equal to undefined or null.

代码片段

const coalesce = (...args) => args.find(v => ![undefined, null].includes(v));

使用样例

coalesce(null, undefined, '', NaN, 'Waldo'); // ''