- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing

- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM

- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers

- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources

# JavaScript program to find area of a circle

We will be using the below formula to find the area of a circle −

pi * r^2

In the program, we will prompt the user to input the radius of the circle. Then, we will use the formula to calculate the area and print it on the screen.

## Approach

Get the radius of the circle from the user as an input.

Calculate the area using the formula: area = π * radius^2

Store the value of π, it can be calculated using Math.PI in JavaScript.

Multiply the value of π with the square of the radius to get the area.

Round off the result to required decimal places, if necessary, using the toFixed() method.

Return or print the calculated area.

## Example

Here is an example of a JavaScript program that calculates the area of a circle

const radius = 10; const pi = Math.PI; const areaOfCircle = (radius, pi) => { return pi * radius * radius; }; console.log("The area of the circle is: " + areaOfCircle(radius, pi));

## Explanation

First, we declare two constants:

**radius**and**pi**. The**radius**constant is assigned the value**10**, and**pi**is assigned the value of**Math.PI**which is a built-in constant in JavaScript that represents the value of pi (3.14159...).Next, we define a function named

**areaOfCircle**that takes two parameters**radius**and**pi**.Inside the function, we use the formula for the area of a circle, which is

**pi * radius * radius,**and return the result.Finally, we use

**console.log()**to display the result of calling**areaOfCircle**with**radius**and**pi**as arguments. The result is a string that says "The area of the circle is: [area]".This program calculates the area of a circle with a radius of 10 and outputs the result to the console.

- Related Articles
- Java program to find the area of a circle
- Python Program to find the area of a circle
- Swift Program to Find the Area of a Circle
- Kotlin Program to Find the Area of a Circle
- C Program for Program to find the area of a circle?
- Find the Area of a Circle in Java Program
- Java Program to Find Area of circle Using Method Overloading
- C program to find the area of circle and cylinder using structures.
- JavaScript program to find Area and Perimeter of Rectangle
- How to find the Area of a Circle in Golang?
- How to calculate the area and perimeter of a circle in JavaScript?
- Calculate difference between circumference and area of a circle - JavaScript
- Program to calculate the area of an Circle inscribed in a Square
- Find the area of a circle in C programming.
- Swift Program to Calculate Area of Circle Inscribed in Square