Home  >  Article  >  Web Front-end  >  What is the function to find the nth power in javascript?

What is the function to find the nth power in javascript?

青灯夜游
青灯夜游Original
2021-11-08 16:39:244250browse

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)".

What is the function to find the nth power in javascript?

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));

1 (1).png

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.

What is the function to find the nth power in javascript?

[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!

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