ES6学习笔记(三)------------------------------------常用的字符串和值扩展的for...of循环用于遍历字符串letstr="welcometoBeiJing";for(valofstr){console.log(val)}//welcometoBeiJingNumber.isFinite).()用于检查一个数是否是有限的(finite)Number.isFinite(15);//trueNumber.isFinite(0.8);//trueNumber.isFinite(NaN);//falseNumber.isFinite(Infinity);//假数字。是有限的(-无穷大);//falseNumber.isFinite('foo');//falseNumber.isFinite('15');//falseNumber.isFinite(true);//falseNumber.isNaN(NaN)//trueNumber.isNaN(15)//falseNumber.isNaN('15')//falseNumber.isNaN(true)//falseNumber.isNaN(9/NaN)//trueNumber.isNaN('true'/0)//trueNumber.isNaN('true'/'true')//trueNumber.parseInt()用于将数字或字符串转换为整数Number.parseInt("123")//123Number.parseInt(10.23112)//10Number.parseInt(NaN)//NaNNumber.parseInt("aw123d")//NaNNumber.parseInt("123d")//123Number.parseInt("aw123")//NaNNumber.parseFloat()将包含浮点数的字符串转换为浮点数Number.parseFloat("123.45da")//123.45Number.parseFloat("123.00da")//123Number.parseFloat("123.45")//123.45Number.parseFloat("123.00")//123ItshouldbenotedthatinsideJavaScript,integersandFloatingpointnumbersarestoredinthesameway,so3and3.0aretreatedasthesamevalueNumber.isInteger()isusedtodeterminewhetheravalueisanintegerNumber.isInteger(25)//trueNumber.isInteger(25.0)//trueNumber.isInteger(25.1)//falseNumber.isInteger("15")//falseNumber.isInteger(true)//falseNumber.EPSILONisaverysmallvariableaddedbyES6tojudgetheaccuracyofdecimalNumber.EPSILON2.220446049250313e-16Number.MAX_SAFE_INTEGER表示js允许的最大值,Number.MIN_SAFE_INTEGER表示js允许的最小值Number.MAX_SAFE_INTEGER9007199254740991Number.MIN_SAFE_INTEGER-9007199254740991Number.isSafeInteger()判断一个数是否超出js允许的范围Number.isSafeInteger(-9007199254740991)//trueNumber.isSafeInteger(-90071992547409921)//falseMath.truncmethodisusedtoremovethedecimalpartofanumberandreturntheintegerpartMath.trunc(4.1)//4Math.trunc(4.9)//4Math.trunc(-4.1)//-4Math.trunc(-4.9)//-4Math.trunc(-0.1234)//The-0Math.signmethodisusedtodeterminewhetheranumberispositive,negative,orzero.Fornon-numericvalues,itwillbeconvertedtoanumericalvaluefirst.ParametersIfthevalueispositive,return+1;iftheparameterisnegative,return-1;iftheparameteris0,return0;iftheparameteris-0,return-0;forothervalues,returnNaN.Math.sign(-5)//-1Math.sign(5)//+1Math.sign(0)//+0Math.sign(-0)//-0Math.sign(NaN)//NaNMath.sign('9');//+1Math.sign('foo');//NaNMath.sign();//NaNMath.cbrt方法用于计算数字的立方根Math.cbrt(-1)//-1Math.cbrt(0)//0Math.cbrt(1)//1Math.cbrt(2)//1.2599210498948734Math.hypot方法返回所有参数的平方和的平方根Math.hypot(3,4);//5Math.hypot(3,4,5);//7.0710678118654755Math.hypot();//0Math.hypot(NaN);//NaNMath.hypot(3,4,'foo');//NaNMath.hypot(3,4,'5');//7.0710678118654755Math.hypot(-3);//3Math.expm1(x)返回ex-1,即Math.exp(x)-1Math.expm1(-1)//-0.6321205588285577Math.expm1(0)//0Math.expm1(1)//1.718281828459045Math.log1p(x)方法返回1+x的自然对数,即Math.log(1+x)。如果x小于-1,返回NaNMath.log1p(1)//0.6931471805599453Math.log1p(0)//0Math.log1p(-1)//-InfinityMath.log1p(-2)//返回NaNMath.log10(x)x的以10为底的对数。如果x小于0,返回NaNMath.log10(2)//0.3010299956639812Math.log10(1)//0Math.log10(0)//-InfinityMath.log10(-2)//NaNMath.log10(100000)//5Math.log2(x)返回x的以2为底的对数。如果x小于0,返回NaNMath.log2(3)//1.584962500721156Math.log2(2)//1Math.log2(1)//0Math.log2(0)//-InfinityMath.log2(-2)//NaNMath.log2(1024)//10Math.log2(1<<29)//29Math.sinh(x)返回x的双曲正弦Math.cosh(x)返回x的双曲余弦)Math.tanh(x)返回x的双曲正切值Math.asinh(x)返回x的反双曲正弦值Math.acosh(x)返回x的反双曲余弦值hyperboliccosine)Math.atanh(x)返回x的反双曲正切值(inversehyperbolictangent)Math.sign()用于判断一个值是正还是负,但是如果参数为-0,则返回-0Math.sign(-0)//-0ES2016增加了一个指数运算符**2**2//42**3//8leta=1.5;a**=2;//等价于a=a*a;letb=4;b**=3;//等价于b=b*b*b;
