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'); // ''
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️