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 passed parameter value is a finite number; the syntax is "Number.isFinite(value)".
The operating environment of this tutorial: Windows 7 system, ECMAScript version 6, Dell G3 computer.
ES6 provides us with a method to determine numbers. For details, see the code below.
Number.isFinite determines numbers.
The Number.isFinite() method is used to detect whether the incoming 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 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
If you need to determine whether it is a floating point type, just add the negation sign in front of the object
let a = 111.77 console.log(!Number.isInteger(a)); // The safe value range of true
safe integers
in computer numerical types is 2 to the 53rd power.
let num = Math.pow(2, 53) - 1; console.log(num) // 9007199254740991
Why does ES6 provide constants for the maximum safe integer and the minimum safe integer? You can also use the isSafeInteger method to determine whether the incoming value is within the safe integer range. In daily work, if this number is exceeded, We need to convert this value into a string and display it to the user
console.log(Number.MAX_SAFE_INTEGER) // 9007199254740991 console.log(Number.MIN_SAFE_INTEGER) // -9007199254740991 // Determine whether num is within the safe integer range console.log(Number.isSafeInteger(num)) // true