Files
30-seconds-of-code/snippets/coalesce.md
Angelos Chalaris 5c2eeb3bcc Updated examples
2017-12-27 16:06:16 +02:00

280 B

coalesce

Returns the first non-null/undefined argument.

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

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