ES6如何新增math,Number方法

发布时间:2021-07-28 09:56:17 作者:小新
来源:亿速云 阅读:134

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

推荐阅读:
  1. Java中Number和Math类的使用以及比较
  2. ES6 新增的创建数组的方法(小结)

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

es6 math number

上一篇:keep-alive原理的示例分析

下一篇:JavaScript函数参数的传递方式有哪些

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》