ES6新增的math,Number方法

网络编程 发布日期:2024/9/29 浏览次数:1

正在浏览:ES6新增的math,Number方法

ES6新增的math,Number方法,下面总结了一些我觉得有用的

Nunber.isInteger()判断是否为整数,需要注意的是1,和1.0都会被认为是整数

console.log(Number.isInteger(1.0))//true
console.log(Number.isInteger(1))//true
console.log(Number.isInteger("1"))//false
console.log(Number.isInteger("1.1"))//false

Math.sign()判断是正数,负数,还是0

console.log(Math.sign(1))//1
console.log(Math.sign(-1))//-1
console.log(Math.sign(0))//0
console.log(Math.sign(-0))//0
console.log(Math.sign(NaN))//NaN
console.log(Math.sign(undefined))//NaN
console.log(Math.sign(null))//0

Math.cbrt()计算一个数的立方根

console.log(Math.cbrt(8))//2
Math.hypot()返回所有参数的平方和的平方根
console.log(Math.hypot(4,3))//25再开方结果为5 

指数运算

console.log(2**2) //4     
console.log(2**3) //8 

总结

以上所述是小编给大家介绍的ES6新增的math,Number方法,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。