Returns the first non-null and non-undefined value from the provided array of values. If all values in the array are null or undefined, returns the specified default value.
The type of the values and the default value.
An array of values to coalesce.
The default value to return if all values in the array are null or undefined.
The first non-null and non-undefined value from the array, or the default value if all are null or undefined.
const result = coalesceOrDefault([null, undefined, 'hello', 'world'], 'default');console.log(result); // Output: 'hello' Copy
const result = coalesceOrDefault([null, undefined, 'hello', 'world'], 'default');console.log(result); // Output: 'hello'
const result = coalesceOrDefault([null, undefined], 'default');console.log(result); // Output: 'default' Copy
const result = coalesceOrDefault([null, undefined], 'default');console.log(result); // Output: 'default'
Returns the first non-null and non-undefined value from the provided array of values. If all values in the array are null or undefined, returns the specified default value.