how to check if a variable is a number js code example

Example 1: javascript check if variable is number

function isNumber(n) {
  return !isNaN(parseFloat(n)) && !isNaN(n - 0);
}

Example 2: javascript check if a value is a integer number

Number.isInteger(123) //true
Number.isInteger(-123) //true
Number.isInteger(5-2) //true
Number.isInteger(0) //true
Number.isInteger(0.5) //false
Number.isInteger('123') //false
Number.isInteger(false) //false
Number.isInteger(Infinity) //false
Number.isInteger(-Infinity) //false
Number.isInteger(0 / 0) //false