Files
30-seconds-of-code/snippets/coalesce.md
Angelos Chalaris 611729214a Snippet format update
To match the starter (for the migration)
2019-08-13 10:29:12 +03:00

328 B

title, tags
title tags
coalesce utility,beginner

Returns the first non-null/undefined argument.

Use Array.prototype.find() to return the first non null/undefined argument.

const coalesce = (...args) => args.find(_ => ![undefined, null].includes(_));
coalesce(null, undefined, '', NaN, 'Waldo'); // ""