Thursday, September 4, 2025
HomeData Modelling & AIJavaScript program to find area of a circle

JavaScript program to find area of a circle

Given the radius of a circle, find the area of that circle. The area of a circle can simply be evaluated using the following formula:

Area of circle

Where r is the radius of the circle and it may be in float because the value of the pie is 3.14

Approach: Using the given radius, find the area using the above formula: (pi * r * r) and print the result in float.

Example: Below is the example that will illustrate the program to find area of a circle:

Javascript




<script>
    let pi = 3.14159265358979323846;
 
    // Function to calculate the area of circle
    function findArea(r) {
        return (pi * r * r);
    }
 
    // Driver code
    let r, Area;
    r = 5;
 
    // Function calling
    Area = findArea(r);
 
    // displaying the area
    console.log("Area of Circle is: " + Area);
</script>


Output:

Area of Circle is: 78.53981633974483

Time Complexity: O(1).
Auxiliary Space: O(1), since no extra space has been taken.

Another Approach: Using Math.Pi

We can get the value of pi using the Math module in javascript

Below is the Implementation:

Javascript




<script>
 
  function findArea(r) {
          let pie_value = Math.PI;
          return (pie_value * r * r);
   }
 
  // Driver code
  let r, Area;
  r = 5;
 
  // Function calling
  Area = findArea(r);
 
  // displaying the area
  console.log("Area of Circle is: " + Area);
 
</script>


Output:

Area of Circle is: 78.53981633974483
Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

RELATED ARTICLES

Most Popular

Dominic
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6715 POSTS0 COMMENTS