Resolves a value as per resolve, however If an error is thrown or the resolution results in undefined or NaN, fallbackValue is returned instead.
fallbackValue
null is an allowed return value.
null
// Function returns undefined 50% of the time or 0const fn = () => { if (Math.random() >= 0.5) return; // undefined return 0;}const r = resolveWithFallback(fn, 1);const value = r(); // Always 0 or 1 Copy
// Function returns undefined 50% of the time or 0const fn = () => { if (Math.random() >= 0.5) return; // undefined return 0;}const r = resolveWithFallback(fn, 1);const value = r(); // Always 0 or 1
Thing to resolve
Fallback value if an error happens, undefined or NaN
Rest
Resolves a value as per resolve, however If an error is thrown or the resolution results in undefined or NaN,
fallbackValue
is returned instead.null
is an allowed return value.