Multiple choice technology web technology

How to check if a value is a number?

  1. if (isNumeric(numberVar)) {}

  2. if (!isNaN(numberVar)) {}

  3. if (isNumber(numberVar)) {}

  4. if (type(numberVar)=='Number') {}

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The isNaN() function returns true if a value cannot be converted to a valid number. Using !isNaN(value) checks if the value IS numeric because isNaN first attempts to convert the value to a number. Options A and C reference non-existent functions, and option D has incorrect syntax (should be typeof, not type).