Home > Web Front-end > JS Tutorial > body text

An explanation of the new math and Number methods in JavaScript ES6

巴扎黑
Release: 2017-08-08 09:36:32
Original
1791 people have browsed it

The new math and Number methods in ES6, I think they are very good. Friends who need them can refer to them.

The new math and Number methods in ES6 are summarized below. Some of them I think are useful

Nunber.isInteger() determines whether it is an integer. It should be noted that 1 and 1.0 will be considered integers


##

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
Copy after login

Math.sign() Determine whether it is a positive number, a negative number, or 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
Copy after login

Math.cbrt() calculates the cube root of a number


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

Exponential operation

console.log(2**2) //4     
console.log(2**3) //8
Copy after login

The above is the detailed content of An explanation of the new math and Number methods in JavaScript ES6. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template