Home >Web Front-end >JS Tutorial >Introduction to new features of numerical expansion
Numerical expansion mainly adds some new features, such as new methods and method adjustments
1. Binary numerical representation (use 0B as the prefix, b is indifferent Uppercase and lowercase) Octal numerical representation (use 0o as prefix)
{ console.log('B',0B111110111); console.log(0o767); }
2. Number.isFinite (finite) Number. isNaN (not a number)
{ console.log('15',Number.isFinite(15));//true console.log('NaN',Number.isFinite(NaN));//false console.log('1/0',Number.isFinite('true'/0));//false console.log('NaN',Number.isNaN(NaN));//true console.log('0',Number.isNaN(0));//false}
3. Number.isInteger (determine whether it is an integer, note: the received parameter must be a number)
{ console.log('25',Number.isInteger(25));//true console.log('25.0',Number.isInteger(25.0));//true console.log('25.1',Number.isInteger(25.1));//false console.log('25.1',Number.isInteger('25'));//false }
4. Number.MAX_SAFE_INTEGER (2 to the 53rd power) Number.MIN_SAFE_INTEGER (2 to the -53rd power) (these two are the upper and lower integers)
You can use Number.isSafeInteger to determine whether it is within the above range
{ console.log(Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER); console.log('10',Number.isSafeInteger(10));//true console.log('a',Number.isSafeInteger('a'));//false }
5. Math.trunc (get The integer part of the decimal is not rounded)
{ console.log(4.1,Math.trunc(4.1));//4 console.log(4.9,Math.trunc(4.9));//4 }
6. Math.sign (Judge positive and negative numbers, return -1 for negative number, return 0 for 0, return 1 is a positive number)
{ console.log('-5',Math.sign(-5));//-1 console.log('0',Math.sign(0));//0 console.log('5',Math.sign(5));//1 console.log('50',Math.sign('50'));//1(传递的参数为字符串数字 仍然当做数字) console.log('foo',Math.sign('foo'));//NaN(传递的参数是字符串 返回NaN) }
7. Math.cbrt (returns the cube root of a number)
{ console.log('-1',Math.cbrt(-1));//-1 console.log('8',Math.cbrt(8));//2 }
There are also some new APIs such as trigonometric functions and logarithms, which are not listed here
The above is the detailed content of Introduction to new features of numerical expansion. For more information, please follow other related articles on the PHP Chinese website!