Home > Article > Web Front-end > How to implement power calculation in javascript
In JavaScript, you can use the pow() method of the Math object to implement power calculations. "Math.pow()" is an exponentiation function, and the syntax is "Math.pow(x,y)" , can return the value of x raised to the power of y.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In JavaScript, if you want to perform power calculations, you can use the pow()
method of the Math object. Math.pow()
is the exponentiation function
The syntax is
Math.pow(x,y)
x Required. base. Must be a number.
#y Required. Power number. Must be a number.
can return a value representing x raised to the power of y.
Example:
console.log(Math.pow(0, 1)); console.log(Math.pow(1, 0)); console.log(Math.pow(1, 1)); console.log(Math.pow(1, 10)); console.log(Math.pow(3, 3)); console.log(Math.pow(-3, 3)); console.log(Math.pow(2, 4));
Note: If the result is an imaginary or negative number, this method will return NaN. If a floating point overflow occurs due to an exponent that is too large, this method returns Infinity.
[Recommended learning: javascript advanced tutorial]
The above is the detailed content of How to implement power calculation in javascript. For more information, please follow other related articles on the PHP Chinese website!