Home  >  Article  >  Web Front-end  >  An explanation of the new math and Number methods in JavaScript ES6

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

巴扎黑
巴扎黑Original
2017-08-08 09:36:321792browse

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

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

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

Exponential operation

console.log(2**2) //4     
console.log(2**3) //8

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!

Statement:
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