ES6如何新增math,Number方法

2023-06-12,,

这篇文章将为大家详细讲解有关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方法”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

《ES6如何新增math,Number方法.doc》

下载本文的Word格式文档,以方便收藏与打印。