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.
- Verify that the type is strictly a
number. - Verify that the number is finite (not Infinity or -Infinity).
- Verify that the value is not
NaN. - Return
trueonly if all conditions are met.
01EXAMPLE 1
Input
val = NaNOutput
falseExplanation: NaN is a number type, but it is not a safe math value.
Constraints
- Use Number.isFinite() or similar logic.
- Return a boolean.
MathTypesMastery
JavaScriptSystem handles I/O — write your function only
Loading...
4 Hidden
Input Arguments
valnull
Expected Output
false
Click RUN to test your solution