How to use the Math.pow() Method In Javascript
This is another method to method that is used to power a number i.e., the value of the number raised to some exponent. Here, we will use this method to calculate the power of the number.
Syntax
Math.pow(base, exponent);
Example: In this example, we will calculate 7 to power 9 using Math.pow() method.
// Base number input
let n = 7;
let power = 9;
// Calculate and display output
console.log(Math.pow(n,power));
Output
40353607
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 to which the power is to be raised. These programs will have input numbers and power and will show the resulting output. There are various techniques to calculate the power of a number, which are described below with their illustrations.
Table of Content
- Using JavaScript Loops
- Using Recursion
- Using the Math.pow() Method
- Using JavaScript Exponentiation (**) Operator
- Using Exponentiation by Squaring