The newest way is the exponentiation operator
**, available with ES2016 or higher.
For example, we can do this:
const a = 2 ** 3; // 8
It is right associative, so
a ** b ** c is equal to
a ** (b ** c). This works with all exponents.
const a = 2 ** (3 ** 4); const b = 2 ** 3 ** 4; a == b // true, both are 2.4178516392292583e+24
We can also use the
Math.pow function, like this:
const a = Math.pow(2,3) // 8
It takes 2 arguments, the first is the base and the second is the exponent.
Math.pow works with all exponents.
Math.pow is compatible with all recent browsers.