Skip to content

JavaScript Math pow() Function | get the power of a number

JavaScript Math pow() function is used to raise to a certain power of the number. This method returns the value of x to the power of y (xy), i.e. baseexponent.

Math.pow(base, exponent)

base – The base number

exponent – The exponent that is used to raise the base

Note: negative bases with fractional exponents always return NaN.

JavaScript Math pow() example

Simple HTML example code.

<!DOCTYPE html>
<html>
<head>

  <script>
    let x = Math.pow(4, 3);

    console.log(x); 
  </script>
</head>
<body>

</body>
</html>

Output:

JavaScript Math pow() Function

More example

console.log(Math.pow(7, 3));
// 343

console.log(Math.pow(4, 0.5));
// 2

console.log(Math.pow(7, -2));
// 0.02040816326530612
// (1/49)

console.log(Math.pow(-7, 0.5));
// NaN

Do comment if you have any doubts or suggestions on this JS math power topic.

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

OS: Windows 10

Code: HTML 5 Version

1 thought on “JavaScript Math pow() Function | get the power of a number”

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading