ES6新增的math,Number方法

网络编程 2021-07-04 18:33www.168986.cn编程入门
ES6新增的math,Number方法,长沙网络推广觉得非常不错,需要的朋友参考下吧

ES6新增的math,Number方法,狼蚁网站SEO优化总结了一些我觉得有用的

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方法,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,长沙网络推广会及时回复大家的!

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by

长沙网络推广|微博营销|长沙seo优化|视频营销|长沙网络营销|微信营销|长沙网站建设|口碑营销|软文营销