How to calculate the perimeter and area of a circle using JavaScript?

In this article, we will see how to calculate the perimeter and area of a circle using JavaScript. The mathematical formula for calculating the perimeter and area of the circle is given below:

Area of circle = π * r * r

Perimeter of circle = 2 * π * r

Both formulae require the value of PI. So, in JavaScript, we have to use Math.PI property to get the value of PI.

Let's see an example to calculate the perimeter and area of the circle.

Example

In this example, the radius of the circle is 20cm. We have to click the given HTML button to get the area and perimeter.

Test it Now

Output

After the execution of above code and clicking the given button the output will be -

How to calculate the perimeter and area of a circle using JavaScript




Latest Courses