Function coalesce

Returns first non-nil (not undefined, not null) value from given arguments.

coalesce(null, undefined, void 1, 5); // returns 5 (mind the `void`)
coalesce(0, null, 6, undefined); // returns 0
coalesce(undefined); // returns null
coalesce(); // returns null
  • Type Parameters

    • T

    Parameters

    • Rest...args: T[]

      values

    Returns null | NonNullable<T>

    first non-nil value or null