Exponentiation (Math.pow or **)
suggest changeExponentiation raises the first operand to the power of the second (a**b).
const a = 2;
const b = 3;
const c = Math.pow(a, b);
c will now be 8
The ** operator has been standard since ES2016:
const a = 2;
const b = 3;
const c = a ** b;
c will now be 8
Use Math.pow to find the nth root of a number.
Finding the nth roots is the inverse of raising to the nth power. For example 2 to the power of 5 is 32. The 5th root of 32 is 2.
Math.pow(v, 1 / n); // where v is any positive real number
// and n is any positive integer
const a = 16;
const b = Math.pow(a, 1 / 2); // return the square root of 16 = 4
const c = Math.pow(a, 1 / 3); // return the cubed root of 16 = 2.5198420997897464
const d = Math.pow(a, 1 / 4); // return the 4th root of 16 = 2
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents