Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
JavaScript Program to Find Area of a Circle
To find area of a circle using javascript, we will be using simple formulae of calculating the area of circle. The formula used is: Area = ? × r² where r is the radius and ? is a constant value pi.
In this article, we are having radius of the circle and our task is to find the area of the circle using JavaScript.

Example
let radius = 10 and ?(pi) = 3.1415926535 Area = ? × r² Area= 3.1415926535 * 10 * 10 Area= 314.15926535
Steps to Find Area of Circle
- We have stored radius of circle and pi value in variable radius and pi.
- Then we have defined a function areaCircle() to find the area. It takes p and r as arguments which represents pi and radius respectively.
- It returns the area of circle by multiplying pi with square of radius.
- The area of the circle is calculated by calling the areaCircle() function and passing pi and radius as arguments.
- The output is displayed in web console using console.log().
Example 1
This example demonstrates the implementation of the above steps to find the area of the circle using JavaScript.
let radius = 10;
let pi = 3.141592653589793238;
function areaCircle(p, r){
return p *r *r;
}
let area = areaCircle(pi, radius)
console.log("The area of the circle is: " + area);
Example 2
In this example, we have used Math functions for pi value and to calculate the square of radius using Math.PI and Math.pow() respectively.
let radius = 10;
let pi = Math.PI;
function areaCircle(p, r){
return p * Math.pow(r, 2);;
}
let area = areaCircle(pi, radius)
console.log("The area of the circle is: " + area);
Practice and learn from a wide range of JavaScript examples, including event handling, form validation, and advanced techniques. Interactive code snippets for hands-on learning.
Advertisements
