basic
Math.pow
Returns base raised to the power of exponent. In modern code the `**` operator (ES2016) is usually preferred for readability and identical semantics.
Math.pow(base, exponent) Parameters & edge cases
| Case | Behavior |
|---|---|
| base | The base number |
| exponent | The power; can be fractional (roots) or negative (reciprocals) |
| ** operator | `base ** exponent` is the modern equivalent — same result, no lookup |
Examples
console.log(Math.pow(2, 10)); // 1024 2 to the 10th.
console.log(Math.pow(2, -1)); // 0.5 Negative exponent yields reciprocal.
console.log(Math.pow(4, 0.5)); // 2 Fractional exponent computes a root — here, the square root.
console.log(2 ** 10); // 1024 ES2016 exponent operator, identical result.
Gotcha
Math.pow(-1, 0.5) returns NaN (no real root). Math.pow THROWS TypeError on BigInt arguments — use the `**` operator (e.g. `2n ** 10n`) for BigInt exponentiation.
Related
Math.sqrt
Returns the positive square root of a number. Equivalent to Math.pow(x, 0.5) but faster and clearer.
Math.cbrt
Returns the cube root of a number. Introduced in ES2015, and unlike sqrt it handles negative inputs correctly.
Math.exp
Returns e^x, where e is Euler's number (~2.71828). The inverse of Math.log (the natural logarithm).
Math.abs
Returns the absolute value of a number — its distance from zero without regard to sign. Useful for differences, magnitudes, and tolerance checks.
Math.hypot
Returns the square root of the sum of squares of its arguments — the Euclidean norm. Introduced in ES2015 and safer than manual sqrt(a*a + b*b) against overflow.