C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Math pow() methodThe JavaScript math pow() method returns the base to the exponent power such as baseexponent. In other words, the base value (x) is multiplied with itself exponent times (y). SyntaxThe pow() method is represented by the following syntax: Math.pow(base,exponent) ParameterBase - The base number. Exponent - The number used to raise the base. ReturnThe value of base to the power of exponent. JavaScript Math pow() method exampleHere, we will understand pow() method through various examples. Example 1Let's see a simple example to print the power of given number. <script> document.writeln(Math.pow(2,3)+"<br>"); document.writeln(Math.pow(5,1.4)); </script> Output: 8 9.518269693579391 Example 2Let's see an example to understand the pow() method with different test cases. <script> document.writeln(Math.pow(2,-3)+"<br>"); document.writeln(Math.pow(-3,2)+"<br>"); document.writeln(Math.pow(-5,1.4)+"<br>"); document.writeln(Math.pow(5,-1.4)); </script> Output: 0.125 9 NaN 0.1050611121761507 Example 3Let's understand the pow() method with your own test cases. <script> function display() { var x=document.getElementById("base").value; var y=document.getElementById("exp").value; document.getElementById("result").innerHTML=Math.pow(x,y); } </script> <form> Base: <input type="text" id="base"><br> Exponent: <input type="text" id="exp"> <br> <input type="button" onclick="display()" value="submit"> </form> <p><span id="result"></span></p>
Next TopicJavaScript Math
|