The Universal Fallback

HardAcc. 45.1%
+60 XP 25

The NaN/Null Predator

We've used || for falsy values and ?? for nullish values. But what if a value is NaN (falsy) but not nullish? ?? will not catch NaN!

A "Universal Fallback" chains these operators to ensure that no matter what goes wrong (null, undefined, or a failed math operation resulting in NaN), you always return a valid number.

The Assignment

Your function receives a parameter val.

  1. If val is strictly null or undefined, return the number 0.
  2. If val is a NaN result, return the number 0.
  3. Use a single logical expression (no if statements) combining ?? and || to handle all three safely.

01EXAMPLE 1

Inputval = NaN
Output0

Explanation: NaN is caught and turned to 0.

Constraints

  • Use both ?? and || in the same line.
  • Return 0 for null, undefined, or NaN.
LogicShort-CircuitProfessional
JavaScript
Loading...
3 Hidden

Input Arguments

valnull

Expected Output

0

Click RUN to test your solution