The exponentiation operator

Math.pow() raises a base to an exponent. The recently introduced “exponentiation operator” ** does the same but shorter.

// we can use `Math.pow(x, y)` to calculate x^y
Math.pow(2, 2)     // ⇒  2 ^ 2   =  4
Math.pow(4, 3)     // ⇒  3 ^ 3   = 64
Math.pow(25, 0.5)  // ⇒ 25 ^ 0.5 =  5

// `x ** y` does the same, but shorter
2 ** 2             // ⇒  2 ^ 2   =  4
4 ** 3             // ⇒  4 ^ 3   = 64
25 ** 0.5          // ⇒ 25 ^ 0.5 =  5

There is more to learn

Get free previews of my upcoming course materials and other bonus content to help you work smarter. I share tips straight to your inbox once a week. You can read previous mails in the newsletter archive.

Cannot show form because cookie consent was not given.