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

Parameter

Type

Description

value

T | undefined

The value to be checked

defaultValue

T

The 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