fallbackNumber

fallback

Returns the value if the given value is finite; otherwise, it returns the fallback value.

Import

import { fallbackNumber } from '@fullstacksjs/toolbox';

Signature

function fallbackNumber<T extends number = number>(value: Nullable<T>, fallbackValue: T): NonNullable<T> {}

Examples

fallbackNumber(0, 1)         // 0
fallbackNumber(-1, 1)        // -1
fallbackNumber(1, -1)        // 1
fallbackNumber(-0, 1)        // -0
fallbackNumber(NaN, 1)       // 1
fallbackNumber(Infinity, 1)  // 1
fallbackNumber(-Infinity, 1) // 1