The JavaScript operator you didn't know existed...

NicolasBrondinBernard

Author
@NicolasBrondinBernard

Did you think you knew all the mathematical operators available in JavaScript? Do you know exponentiation?

Article published on 13/02/2023, last updated on 10/08/2026

A few weeks ago, I discovered that an additional mathematical operator has been introduced in JavaScript since ECMAScript 2016, and is therefore supported by all recent browsers.

This operator is: exponentiation, and it's written ** !

Yes, I know, the name doesn't help much in figuring out what it does...

Yet, its use is very simple, and it can be really useful for lightening mathematical expressions in your code. Let's take the Pythagorean theorem as an example:

const a = 4;
const b = 3;
const c = Math.sqrt(Math.pow(a,2) + Math.pow(b,2));
// c = 5

With the ** operator, which lets you calculate a number to the power of n, our expression simply becomes:

const c = (a**2 + b**2) ** 0.5;
// c = 5

For those who, like me, aren't math geniuses, you'll also have learned that a number to the power of 0.5 is equal to its square root...

In short, the ** operator lets you calculate the power of a number, without having to use the Math.pow method!


Thomas T sur Unsplash

Finished reading this article?
Our newsletter

No spam. Only free content, news, and ever more resources to level up your skills!

Join +1500 developers

Comments (0)

to leave a comment

No comments yet