JavaScript Math.pow()
Syntax & Examples


Math.pow() static-method

The Math.pow() method in JavaScript returns the base to the exponent power, that is, base raised to the power of exponent (base^exponent). It is a static method of Math, meaning it is always used as Math.pow() and not as a method of a Math object created (Math is not a constructor).


Syntax of Math.pow()

The syntax of Math.pow() static-method is:

Math.pow(base, exponent)

This pow() static-method of Math returns base x to the exponent power y (that is, x^y).

Parameters

ParameterOptional/RequiredDescription
baserequiredThe base number.
exponentrequiredThe exponent used to raise the base.

Return Type

Math.pow() returns value of type Number.



✐ Examples

1 Using Math.pow() with positive base and exponent

In this example, we use the Math.pow() method to calculate 2 raised to the power of 3.

For example,

  1. We call Math.pow() with 2 and 3 as the arguments.
  2. The method returns 2 raised to the power of 3.
  3. We log the result to the console using console.log().

JavaScript Program

console.log(Math.pow(2, 3));

Output

8

2 Using Math.pow() with a negative base

In this example, we use the Math.pow() method to calculate -2 raised to the power of 3.

For example,

  1. We call Math.pow() with -2 and 3 as the arguments.
  2. The method returns -2 raised to the power of 3.
  3. We log the result to the console using console.log().

JavaScript Program

console.log(Math.pow(-2, 3));

Output

-8

3 Using Math.pow() with a negative exponent

In this example, we use the Math.pow() method to calculate 2 raised to the power of -3.

For example,

  1. We call Math.pow() with 2 and -3 as the arguments.
  2. The method returns 2 raised to the power of -3.
  3. We log the result to the console using console.log().

JavaScript Program

console.log(Math.pow(2, -3));

Output

0.125

Summary

In this JavaScript tutorial, we learned about pow() static-method of Math: the syntax and few working examples with output and detailed explanation for each example.