Course contentsShow
← JavaScript
Lesson 141 of 2,7234. Working with NumbersFree lesson

Math.pow and the Exponentiation Operator

Raising numbers to powers using Math.pow and the ** operator, understanding their equivalence.

Math.pow and the Exponentiation Operator

You'll learn how to raise numbers to powers using two equivalent methods in JavaScript.


The Core Idea

Sometimes you need to calculate powers: 2 to the power of 3 (2³ = 8), or 5 squared (5² = 25). JavaScript gives you two ways to do this: the older Math.pow() method and the newer ** operator (called the exponentiation operator).

Think of exponentiation like repeated multiplication: 2³ means "multiply 2 by itself 3 times" (2 × 2 × 2 = 8).

Using Math.pow

Math.pow() takes two arguments: the base and the exponent.

Math.pow(2, 3);   // 8 (2 × 2 × 2)
Math.pow(5, 2);   // 25 (5 × 5)
Math.pow(10, 4);  // 10000 (10 × 10 × 10 × 10)
Math.pow(3, 0);   // 1 (any number to the power of 0 is 1)

Using the ** Operator

The ** operator does exactly the same thing but with cleaner syntax:

2 ** 3;   // 8
5 ** 2;   // 25
10 ** 4;  // 10000
3 ** 0;   // 1

They're Equivalent

These produce identical results:

Math.pow(7, 2) === 7 ** 2;  // true, both equal 49
Math.pow(2, 8) === 2 ** 8;  // true, both equal 256

The ** operator is generally preferred today because it's more concise and readable, matching the mathematical notation you'd see on paper.

Fractional and Negative Exponents

Both methods work with decimals and negative numbers:

4 ** 0.5;       // 2 (square root of 4)
2 ** -1;        // 0.5 (same as 1/2)
Math.pow(9, 0.5);  // 3 (square root of 9)

Key Takeaway: Use Math.pow(base, exponent) or the ** operator to raise numbers to powers—they're functionally identical, but ** is more modern and concise.