Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

In ES5, we have several global functions isNaN function, isFinite function, parseInt function, parseFloat function, etc. It is easy to use these global functions. In the ES6 standard, however, these methods are ported to the Number object, which is the function under the global object Window, as well as isFinite, parseInt, and parseFloat. Here are a few examples:

{// Binary representation of es6, starting with 0b console.log('B',0B111110111); // B 503 // es6 octal notation starting with 0o console.log(0o767); // B 503 // es6 octal notation starting with 0o console.log(0o767); // Check whether console.log('15', number.isfinite (15)); // 15 true console.log('NaN',Number.isFinite(NaN)); // NaN false console.log('1/0',Number.isFinite('true'/0)); Log ('NaN', number.isnan (NaN)); // 1/0 false // Check whether console.log('NaN', number.isnan (NaN)); // NaN true console.log('0',Number.isNaN(0)); Log ('25', number.isINTEGER (25)); / / 25 true on the console. The log (' 25.0 'Number. IsInteger (25.0)); / / 25.0 true on the console. The log (' 25.1 'Number. IsInteger (25.1)); Log ('25', number.isINTEGER ('25')); // 25 false} {// MAX_SAFE_INTEGER and MIN_SAFE_INTEGER are both constants console.log(Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER); // 10 is a safe Number in the MAX_SAFE_INTEGER and MIN_SAFE_INTEGER ranges console.log('10', number.issafeINTEGER (10)); // 10 true // a is not a Number console.log('a', number.isSafeINTEGER ('a')); // a false} // es6 takes only integer parts {console.log(4.1, math.trunc (4.1)); / / 4.1 4 console. The log (4.9, math.h trunc (4.9)); / / 4.9 4} / / judgment of plus or minus {the console. The log (' - 5 'Math. Sign (5)); // -5 -1 console.log('0',Math.sign(0)); // 0 0 console.log('5',Math.sign(5)); // 5 1 console.log('50',Math.sign('50')); // 50 1 console.log('foo',Math.sign('foo')); / / / / foo NaN} the computation of cube root {the console. The log (' 1 ', Math. CBRT (1)); // -1 -1 console.log('8',Math.cbrt(8)); / / 8 2}Copy the code