Argument coalescing

JavaScript, Type · Sep 15, 2020

Returns the first defined, non-null argument.

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

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

More like this