

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to calculate the nth root of a number in JavaScript?
To calculate the end root of a number, use Math.abs() method. Here, we’re using the Match.pow method also. You can try to run the following code to calculate the square root of numbers in JavaScript −
Example
<html> <head> <title>Calculate root</title> </head> <body> <script> function displayRoot(x, num) { val = num % 2; if((val == 1) || x < 0) x = -x; var a, num; a = Math.pow(x, 1 / num); num = Math.pow(a, num); if(Math.abs(x - num) < 1 && (x > 0 === num > 0)) return val ? -a : a; } document.write(displayRoot(36, 2)); document.write("<br>"+displayRoot(49, 2)); document.write("<br>"+displayRoot(36, -2)); document.write("<br>"+displayRoot(216, -2)); </script> -+ </body> </html>
- Related Questions & Answers
- JavaScript to Calculate the nth root of a number
- How to calculate square root of a number in Python?
- How to get the square root of a number in JavaScript?
- How to find the cube root of a number in JavaScript?
- How to calculate the ln of a given number in JavaScript?
- Finding the nth prime number in JavaScript
- 8086 program to find the square root of a perfect square root number
- Find Nth positive number whose digital root is X in C++
- Returning a range or a number that specifies the square root of a number in JavaScript
- Finding the nth element of the lucas number sequence in JavaScript
- Returning the nth even number using JavaScript
- Finding square root of a number without using Math.sqrt() in JavaScript
- Fifth root of a number in C++
- How to get the square root of 2 in JavaScript?
- Java program to calculate the power of a number
Advertisements