Skip to content

Latest commit

 

History

History
20 lines (16 loc) · 726 Bytes

nth-number-root.md

File metadata and controls

20 lines (16 loc) · 726 Bytes
title shortTitle type language tags cover excerpt dateModified
Calculate the nth root of a number in JavaScript
Nth root of number
tip
javascript
math
tree-roots
Use `Math.pow()` to calculate the nth root of a given number in JavaScript.
2024-02-17

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