Check if Variable Is a Number
EasyP3Coding
Implement isNumber(value), which returns true if value is a number and false otherwise.
Rules:
- A primitive number counts, including negatives,
0,-0andInfinity. NaNdoes not count, althoughtypeof NaNis"number".- Numeric strings (
"5"),Numberwrapper objects (new Number(5)),null,undefined, booleans, arrays and BigInt values do not count.
Example 1
- Input
- isNumber(42), isNumber('42'), isNumber(NaN)
- Output
- true, false, false
Constraints
- value can be of any type.
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 7. ⌘Enter runs, ⌘⇧Enter submits.