In es6, you can use the isFinite() method of the Number object to determine whether the value is a number. This method can detect whether the parameter value passed in is a finite number; the syntax "Number.isFinite(value) ".
The operating environment of this tutorial: Windows 7 system, ECMAScript version 6, Dell G3 computer.
ES6 provides us with a method for judging numbers. Please see the following code for details
Number.isFinite Judging numbers
## The #Number.isFinite() method is used to detect whether the passed parameter is a finite number.let a = 1 console.log(Number.isFinite(a)); // true console.log(Number.isFinite("beline")); //false console.log(Number.isFinite(NaN)); // false console.log(Number.isFinite(undefined)); // false
Number.isNaN determines whether it is a non-number
console.log(Number.isNaN(NaN)); // true console.log(Number.isNaN(1)); // false
Number.isInteger determines whether it is an integer
let a = 66 console.log(Number.isInteger(a)); // true
let a = 111.77 console.log(!Number.isInteger(a)); // true
Safe integer
The safe value range of computer numeric types is 2 to the 53rd power.let num = Math.pow(2, 53) - 1; console.log(num ) // 9007199254740991
console.log(Number.MAX_SAFE_INTEGER) // 9007199254740991 console.log(Number.MIN_SAFE_INTEGER) // -9007199254740991 // 判断num是否在安全整数范围内 console.log(Number.isSafeInteger(num)) // true
javascript video tutorial、web front end】
The above is the detailed content of How to determine whether it is a number in es6. For more information, please follow other related articles on the PHP Chinese website!