Implementing Math function and return m^n in JavaScript

We are required to write a JavaScript function that takes in two numbers say m and n. Then function should calculate and return m^n.

For example − For m = 4, n = 3, then

power(4, 3) = 4^3 = 4 * 4 * 4 = 64
power(6, 3) = 216

The code for this will be the following using the power() function in JavaScript −

Example

const power = (m, n) => {
   if(n 

Output

And the output in the console will be −

64
216
Updated on: 2020-11-23T06:32:14+05:30

223 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements