/

HTML / CSS / JavaScript Tutorial

JavaScript Math method: pow()

[this page | pdf | back links]

The pow() method (of the Math object) returns x to the power y. Note, ^ has a different meaning in JavaScript.

 

It has the following syntax with the following parameters:

 

Math.pow(x, y)

 

Parameter

Required / Optional

Description

x

Required

Input value (the base)

y

Required

Input value (the exponent)

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>

<script>
var c = 4.3;
var c2 = 2.2;
document.getElementById("Example").innerHTML =
  'var x = Math.pow(' + c + ', ' + c2 + ')';
document.getElementById("Result").innerHTML = Math.pow(c,c2);
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodMathPow() {
  return !!Math.pow(3, 4);
}


NAVIGATION LINKS
Contents | Prev | Next | JavaScript Numbers and Math


Desktop view | Switch to Mobile