Safe Number Validator

HardAcc. 58.7%
+50 XP 20

Identifying Real Numbers

JavaScript's typeof val === "number" can be misleading. It will return true for NaN (Not a Number) and Infinity. A "Safe Number" for math should be finite and not NaN.

The Assignment

Your function receives a parameter named val.

  1. Verify that the type is strictly a number.
  2. Verify that the number is finite (not Infinity or -Infinity).
  3. Verify that the value is not NaN.
  4. Return true only if all conditions are met.

01EXAMPLE 1

Inputval = NaN
Outputfalse

Explanation: NaN is a number type, but it is not a safe math value.

Constraints

  • Use Number.isFinite() or similar logic.
  • Return a boolean.
MathTypesMastery
JavaScript
Loading...
4 Hidden

Input Arguments

valnull

Expected Output

false

Click RUN to test your solution