Nth root of number

JavaScript, Math · Jan 6, 2021

Calculates the nth root of a given number.

  • Use Math.pow() to calculate x to the power of 1 / n which is equal to the nth root of x.
const nthRoot = (x, n) => Math.pow(x, 1 / n);
nthRoot(32, 5); // 2

Written by Angelos Chalaris

I'm Angelos Chalaris, a JavaScript software engineer, based in Athens, Greece. The best snippets from my coding adventures are published here to help others learn to code.

If you want to keep in touch, follow me on GitHub or Twitter.

More like this