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'); // ''
Would you like to help us improve 30 seconds of code?Take a quick survey
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.