Skip to main content
Version: 3.13.0

Math.pow()

The Math.pow() method returns the value of a base raised to a power.

Syntax

Math.pow(base, exponent)

Parameters

  • base
    • : The base number.
  • exponent
    • : The exponent number.

Return value

A number representing base taken to the power of exponent. Returns NaN in one of the following cases:

  • exponent is NaN.
  • base is NaN and exponent is not 0.
  • base is ±1 and exponent is ±Infinity.
  • base < 0 and exponent is not an integer.

Description

Math.pow() is equivalent to the ** operator, except Math.pow() only accepts numbers.

Math.pow(NaN, 0) (and the equivalent NaN ** 0) is the only case where NaN doesn't propagate through mathematical operations — it returns 1 despite the operand being NaN. In addition, the behavior where base is 1 and exponent is non-finite (±Infinity or NaN) is different from IEEE 754, which specifies that the result should be 1, whereas JavaScript returns NaN to preserve backward compatibility with its original behavior.

Because pow() is a static method of Math, use it as Math.pow(), rather than as a method of a Math object you created (Math is not a constructor).