Skip to content

Latest commit

 

History

History
16 lines (12 loc) · 375 Bytes

coalesce.md

File metadata and controls

16 lines (12 loc) · 375 Bytes
title tags
coalesce
type,beginner

Returns the first defined, non-null argument.

  • Use 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'); // ''