JavaScript code to find a power of a number | Example code

Use the Math.pow (base, exponent ) method to find a power of a number in JavaScript. The pow() method returns the value of x to the power of y (xy).

Math.pow(x, y)
Math.pow(5, 2);

Here is a small example of “Power of a number”

5= 5 * 5, value is 25

he parameters used in Math.pow() method −

  • base (x) − The base number. 
  • exponents (y)− The exponent to which to raise the base.

Example code to find the power of a number

HTML example code.

<!DOCTYPE html>
<html>
<body>

  <script>

    var a = Math.pow(0, 1);
    var b = Math.pow(2, 3);
    var c = Math.pow(1, 5);
    var d = Math.pow(3, 3);
    var e = Math.pow(-3, 3);
    var f = Math.pow(2, 4);

    console.log(a);
    console.log(b);
    console.log(c);
    console.log(d);
    console.log(e);
    console.log(f);

  </script>
</body>
</html>

Output:

JavaScript code to find a power of a number

Do comment if you have any doubts and suggestions on this JS pow topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.