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}`); |
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