How to use Math.pow() function In Javascript

In this approach we will use Math.pow() function in JavaScript which is used to calculate the power of a number. In this case, Math.pow(sideLength, 2) calculates sideLength raised to the power of 2, which is equivalent to sideLength * sideLength, the area of the square.

Syntax:

Math.pow(base, exponent)

Example: The example uses Math.pow() function to calculate area of square. Here it calculate area by raising side length 8 to the power of 2 i.e. 64.

Javascript




const sideLength = 8;
const area = Math.pow(sideLength, 2);
console.log(`The area of the square is: ${area}`);


Output

The area of the square is: 64

JavaScript Program to Find the Area of a Square

In this article, we will see how to find the area of a square in JavaScript if the side of the square is given. A square is a geometric shape with four equal sides and four right angles. The area of a square is calculated by multiplying the length of one side by itself.

Formula of the Area of Square

Area= side * side

Below are the methods by which we can find the area of a square in JavaScript:

Table of Content

  • Using custom function
  • Using an Arrow Function
  • Using Math.pow() function
  • Using Object Literal Property Value Shorthand

Similar Reads

Using custom function

In this approach, we will define a function that takes the side length as an argument and returns the square of the side length, representing the area of the square....

Using an Arrow Function

...

Using Math.pow() function

Here, an arrow function is used to calculate the area of a square. Arrow functions are a concise way to write functions in JavaScript. The function takes a side length parameter and returns the area by multiplying the side length by itself.....

Using Object Literal Property Value Shorthand

...