Returns the first defined, non-null argument.
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'); // ''
JavaScript, Function
Customizes a coalesce function that returns the first argument which is true
based on the given validator.
JavaScript, Type
Checks if the given argument is an async
function.
JavaScript, Type
Checks if the given argument is a generator function.