js if number is valid code example
Example 1: javascript check if variable is number
function isNumber(n) {
return !isNaN(parseFloat(n)) && !isNaN(n - 0);
}
Example 2: To check if a value is a number in JavaScript
const value = 2
isNaN(value) //false
isNaN('test') //true
isNaN({}) //true
isNaN(1.2) //false