# Calculate the nth root of a number in JavaScript

The nth root of a number `x` is a value that, when multiplied by itself `n` times, gives `x`. The nth root can also be expressed as a power of `x`, where `x ^ (1/n)` is equal to the nth root of `x`.

Given this, we can use `Math.pow()` to calculate the nth root of a given number. Simply pass it the number `x` and a power of `1 / n`, and you'll get the nth root of `x`.

```const nthRoot = (x, n) => Math.pow(x, 1 / n);

nthRoot(32, 5); // 2```

## More like this

• Collection · 89 snippets

### Tips & Tricks

A collection of quick tips and tricks to level up your coding skills one step at a time.

• JavaScript ·

### How can I calculate the greatest common divisor & least common multiple in JavaScript?

Use JavaScript to calculate the greatest common divisor and least common multiple of two or more numbers.

• JavaScript ·

### Calculate the quotient and remainder of a division in JavaScript

Implement Python's `divmod()` built-in function in one line of JavaScript.

• JavaScript ·

### Calculate the Euclidean distance in JavaScript

Use JavaScript's `Math.hypot()` to calculate the Euclidean distance between two points.

Start typing a keyphrase to see matching snippets.