Skip to content

Finding nth root of a number in JavaScript

To calculate the end root of a number, use Math.pow() method. We can pass the number and the fractional exponent as arguments to Math.pow().



Math.pow(number, fraction);


Math.pow(256, 1/6); //2.5198420997897464

Math.pow(64, 1/4); //2.82842712474619

You can write a generic function to find the nth root a number like this.

var nthRoot = function (n, root) {
    return Math.pow(n, 1 / root);

console.log(nthRoot(64,4)) //2.82842712474619
See also  Subtree of Another Tree - Leetcode Challenge - Java Solution

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.