Numbers are used to represent both integer and floating-point values.
Numbers are most commonly expressed in literal forms like 255 or 3.14159 ↴
let num1 = 5; → number
let num2 = 2.5; → number
let num3 = num1 + num2;
console.log(num3); returns ↴
7.5 → number
Find the Nth root of a number using the exponentiation operator **
Exponentiation
Exponentiation is the mathematical process of multiplying a number by itself, raised to the power of another number.
number (1 / root)
root number to be multiplied by itself
number number whose root is to be found
To find the root of a number using exponential notation, rewrite the root as a fractional exponent and solve.
For the nth root of a number x write it as x1/n
For example, the square root of 25 is 251/2 = 5
and the cube root of 27 is 271/3 = 36
Exponentiation operator **
The exponentiation operator ** is used to calculate the Nth root of a number.
2√81 same as 811/2
3√27 same as 271/3
4√16 same as 161/4
Using the exponentiation operator.
811/2 → 81 ** (1/2) → 9
271/2 → 27 ** (1/3) → 3
161/2 → 16 ** (1/4) → 2
Initialize a variable to hold the root value.
const num1 = 2; → user input
Initialize a variable to hold the number whose root is to be found.
const num2 = 81; → user input
Define a function findRoot to find the root of a number.
function findRoot(str) {}
The function takes two numbers as input num1, num2 representing the root and the number whose root is to be found.
num1 → number
num2 → root
Using the exponent operator ** return the result of num raised to the power of (1/root)
return num ** (1 / root)
Call the function with ↴
findRoot(num1, num2);
Find the Nth root of a number.
2√81 → find square root of 81
const num1 = 2;
const num2 = 81;
function findRoot(root, num) {
return num ** (1 / root);
}call function
findRoot(num1, num2); returns ↴
9
Alternative to find the square root of a number using built-in Math.sqrt() method ↴
Math.sqrt(81); returns ↴
9