Home > Article > Web Front-end > How to implement n raised to the kth power in javascript
In JavaScript, you can use the pow() function of the Math object to realize n raised to the kth power. The syntax is "Math.pow(n,k)"; the return result of this function is n raised to the kth power. .
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
The pow() method returns x raised to the y power.
The syntax is:
Math.pow(x,y)
The example is as follows:
<html> <head> <meta charset="utf-8"> <title>123</title> </head> <body> <p id="demo">单击按钮显示4*4*4的结果。</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ document.getElementById("demo").innerHTML=Math.pow(4,3); } </script> </body> </html>
Output result:
After clicking the button , Output result:
Related recommendations: javascript learning tutorial
The above is the detailed content of How to implement n raised to the kth power in javascript. For more information, please follow other related articles on the PHP Chinese website!