Math pow() Method - Javascript Math

Javascript examples for Math:pow

Description

The pow() method returns the value of x to the power of y (xy).

Syntax

Math.pow(x, y)

Parameter Values

Parameter Description
x Required. The base
y Required. The exponent

Return Value:

A Number, representing the value of x to the power of y (xy)

The following code shows how to use the pow() function:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//  w ww  . ja  v  a 2s .  co m
    var a = Math.pow(0, 1);
    var b = Math.pow(1, 1);
    var c = Math.pow(1, 10);
    var d = Math.pow(3, 3);
    var e = Math.pow(-3, 3);
    var f = Math.pow(2, 4);

    var x = a + "<br>" + b + "<br>" + c + "<br>" + d + "<br>" + e + "<br>" + f;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials