javascript check variable type is number code example
Example 1: javascript check if variable is number
function isNumber(n) {
return !isNaN(parseFloat(n)) && !isNaN(n - 0);
}
Example 2: if parameter is not number in js
let num1 = 'Hello';
if(isNaN(num1)){
console.log(num1 + ' is not a number');
} else{
console.log(num1 + ' is a number');
}