JavaScript Math.pow() Method

Definition
Math.pow(base, exponent) returns the base raised to the exponent. For example, Math.pow(2, 3) means 2 × 2 × 2, which is 8.
Read the syntax below, then try the three examples to see the method in action.
Syntax
Call the method on Math. Start with this line.
| Call | What it does |
|---|
Math.pow(base, exponent) | Returns base raised to the power of exponent. |
Built into JavaScript. Call Math.pow(...) on the Math object — no import required. Math is not a constructor, so never write new Math().
Library declarations
Parameters
| Parameter | Description |
|---|
| base | Required. The number you want to multiply. |
| exponent | Required. How many times to multiply the base (the power). |
Return Value
| Return Value | Description |
|---|
| Number | base to the power of exponent. Returns NaN if the result is not a real number. |
JavaScript Examples
Example 1 — Basic Powers
Pass a base and an exponent. A fractional exponent like 0.5 means square root.
console.log(Math.pow(2, 3)); // 8
console.log(Math.pow(5, 2)); // 25
console.log(Math.pow(9, 0.5)); // 3
How It Works
- Whole exponent.
Math.pow(2, 3) is 2 × 2 × 2 = 8. - Squaring.
Math.pow(5, 2) is 5 × 5 = 25. - Fraction exponent. An exponent of
0.5 is the same as a square root, so 9 becomes 3. - Always a number. The result is a normal JavaScript number.
Example 2 — Math.pow() vs the ** Operator
Both give the same answer. The ** operator is shorter and common in modern code.
const a = Math.pow(2, 10);
const b = 2 ** 10;
console.log(a); // 1024
console.log(b); // 1024
console.log(a === b); // true
How It Works
- Two ways.
Math.pow(2, 10) and 2 ** 10 both mean 2 to the power of 10. - Same value. Both print
1024. - Strict compare.
a === b is true because the numbers are equal. - Which to use? Use
** for short code. Use Math.pow() when you pass it as a function, like in map.
Example 3 — Negative Exponent, Zero and NaN
A negative exponent gives a fraction. Some inputs have no real answer and return NaN.
console.log(Math.pow(2, -2)); // 0.25
console.log(Math.pow(0, 0)); // 1
console.log(Math.pow(-8, 1 / 3)); // NaN
console.log(Math.pow("abc", 2)); // NaN
How It Works
- Negative exponent.
2 ** -2 means 1 ÷ (2 × 2), which is 0.25. - Zero to the zero. JavaScript returns
1 for Math.pow(0, 0). - No real answer. A negative base with a fraction exponent returns
NaN. - Bad input. The text
"abc" cannot become a number, so the result is NaN.
Compatibility
Browser & Runtime Support
Math.pow is part of the first JavaScript standard (ES1) and is Baseline Widely available in every browser and in Node.js.
✓ Baseline · ES1
Math.pow
Supported in Chrome, Firefox, Safari, Edge, Internet Explorer and Node.js for many years. No polyfill needed.
99% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full supportMath.pow Excellent
Bottom line: Use Math.pow anywhere. It works in all browsers.
Frequently Asked Questions
Math.pow(base, exponent) returns the base raised to the exponent. Math.pow(2, 3) is 8 because 2 x 2 x 2 = 8.
Yes, they give the same result for numbers. 2 ** 3 and Math.pow(2, 3) are both 8. The ** operator is just shorter.
Use an exponent of 0.5. Math.pow(9, 0.5) is 3. You can also use Math.sqrt(9), which is clearer.
A negative number does not have a real fractional power in JavaScript, so the result is NaN. Use Math.cbrt(-8) to get -2 for a cube root.
It is 1. JavaScript follows the common math rule that any number to the power of 0 is 1, including 0.
All of them. It is part of the very first JavaScript standard and works in every browser and in Node.js.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
9 people found this page helpful