1.二进制和八进制 console.log("二进制",0b101); //5 console.log("八进制",0o007); //7 2.Number 是否有限 console.log(Number.isFinite(Infinity)) //false console.log(Number.isFinite(NaN)) //false console.log(Number.isFinite(null)) //false console.log(Number.isFinite(10)) //true 判断NAN console.log(Number.isNaN(10)) //false console.log(Number.isNaN(true)) //false console.log(Number.isNaN(1/'a')) //true 判断整数 console.log(Number.isInteger(10.1)) //false console.log(Number.isInteger(10.0)) //true console.log(Number.isInteger('10.0')) //false console.log(Number.isInteger('10')) //false 表示一个最小的数,等于2的52次方 console.log(Number.EPSILON) console.log(Math.pow(2,-52) === Number.EPSILON) console.log(Number.EPSILON.toFixed(20)) console.log(0.1+0.2 === 0.3) //false js浮点计算有问题 console.log(0.1+0.2 - 0.3 < Number.EPSILON) //false 最大整数,最小整数,安全范围 Number.MAX_SAFE_INTEGER Number.MIN_SAFE_INTEGER Number.isSafeInteger() console.log(Number.MAX_SAFE_INTEGER); console.log(Math.pow(2,53)) console.log(Math.pow(2,53)==Math.pow(2,53)+1) //true JS超出后计算不精确 console.log(Number.MAX_SAFE_INTEGER+1 == Math.pow(2,53)) 3.Math Math.trunc()去除小数 console.log(Math.trunc(3.14)) //3 console.log(Math.trunc(-3.14)) //-3 Math.sign()判断是不是正数 console.log(Math.sign(10)); //1 console.log(Math.sign(-100));//-1 console.log(Math.sign(0));//0 console.log(Math.sign(NaN));//NaN 求一个数的立方根 console.log(Math.cbrt(8))//2 4.**运算符 //指数运算符** console.log(10**2) //100 console.log(2**2**3) //256
二进制和八进制的转换