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"))//falseMath.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()计算一个数的立方根
立即学习“Java免费学习笔记(深入)”;
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
以上就是JavaScript ES6中新增math,Number方法讲解的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号