Home >Web Front-end >Front-end Q&A >What is the function to find the nth power in javascript?
In JavaScript, the function to find the nth power is pow(); the pow() function of the Math object can calculate the nth power value of the specified number, the syntax is "Math.pow(numeric value, n)".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In JavaScript, the function that finds the nth power is pow().
Syntax: Math.pow(x, y)<br>
This function can calculate and return the value of x raised to the power of y, that is, x The value of y power.
console.log(Math.pow(0, 1)); console.log(Math.pow(1, 1)); console.log(Math.pow(2, 1)); console.log(Math.pow(2, 2)); console.log(Math.pow(2, 3));
If the result of the calculation is an imaginary 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 What is the function to find the nth power in javascript?. For more information, please follow other related articles on the PHP Chinese website!