Skip to main content

getDefaultIfUndefined

@h4ad/serverless-adapter > getDefaultIfUndefined

(function) getDefaultIfUndefined

Return the defaultValue whether the value is undefined, otherwise, return the value.

Signature:

export declare function getDefaultIfUndefined<T>(value: T | undefined, defaultValue: T): T;

Parameters

ParameterTypeDescription
valueT | undefinedThe value to be checked
defaultValueTThe default value when value is undefined

Returns:

T

Example

const value1 = getDefaultIfUndefined(undefined, true);
const value2 = getDefaultIfUndefined(false, true);

console.log(value1);
// true
console.log(value2);
// false