JavaScript Program to Calculate Power Using Recursion Last Updated : 15 Apr, 2025 Comments Improve Suggest changes Like Article Like Report A program to calculate power using recursion involves defining a function that recursively multiplies a base number by itself, decrementing the exponent until it reaches 0. The below-listed examples can be utilized to calculate powers using recursion in JavaScript. Table of Content Using RecursionUsing Memoization with RecursionUsing RecursionBasic recursion involves defining a function that calls itself with modified parameters until reaching a base case, where a specific condition is met. This approach simplifies solving complex problems by breaking them down into smaller, self-repeating tasks. Example: The below code recursively calculates the power of the passed base number in JavaScript. JavaScript function myPowerFunction(base, exponent) { if (exponent === 0) { return 1; } const result = base * myPowerFunction(base, exponent - 1); return result; } const b = 2; const e = 4; console.log (`The recursively calculated value of ${b}^${e} is: ${myPowerFunction(b, e)}`); OutputThe recursively calculated value of 2^4 is: 16 Using Memoization with RecursionMemoization optimizes recursive functions by caching computed results. Before computing, the function checks if the result for given inputs exists in the cache it returns the cached result. Otherwise, it computes the power, stores, and returns it. This reduces redundant computations, enhancing performance. Example: The below code will use memoization technique with recursion to improve the performance. JavaScript const memo = {}; function myPowerFunction(base, exponent) { const key = base + ',' + exponent; if (key in memo) { return memo[key]; } if (exponent === 0) { return 1; } const result = base * myPowerFunction(base, exponent - 1); memo[key] = result; return result; } const b = 3; const e = 4; console.log (`The recursively calculated value of ${b}^${e} is: ${myPowerFunction(b, e)}`); OutputThe recursively calculated value of 3^4 is: 81 Comment More infoAdvertise with us Next Article JavaScript Program to Compute Power of a Number K kohliami558i Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Program Similar Reads JavaScript Program to Print N to 1 using Recursion In this article, we will see how to print N to 1 using Recursion in JavaScript. What is Recursion? The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. In the recursive program, the solution to the base 1 min read JavaScript Program to Print 1 to N using Recursion In this article, we will see how to print 1 to N using Recursion in JavaScript. What is Recursion? The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. In the recursive program, the solution to the base 2 min read JavaScript Program to Find Factorial of a Number using Recursion In this article, we are going to learn about finding a Factorial of a Number using Recursion. Calculating the factorial of a number using recursion means implementing a function that calls itself to find the factorial of a given number. The factorial of a non-negative integer "n" is the product of a 2 min read JavaScript Program to Display Fibonacci Sequence Using Recursion In this article, we will explore how to display the Fibonacci sequence using recursion in JavaScript. The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. Recursion is a powerful technique in programming that involves a function calling itself. A recu 3 min read JavaScript Program to Compute Power of a Number In this article, we will demonstrate different approaches for computing the Power of a Number using JavaScript. The Power of a Number can be computed by raising a number to a certain exponent. It can be denoted using a^b, where the 'a' represents the base number & the 'b' represents the number t 3 min read JavaScript Program to Compute Iterative Power of a Number This article will demonstrate how to compute the iterative power of a number using JavaScript. It will include iterative methods to calculate and display the power of a given number. Methods to Compute the Iterative Power of a NumberTable of Content Method 1: Using JavaScript for LoopMethod 2: Using 3 min read Like