How to get the value of PI using JavaScript?

PI is a mathematical constant. The lowercase Greek letter π represents the symbol PI. It is an acronym of the periphery.

PI can be defined as the circumference (C) of a circle divided by its diameter (d). It means that for any size of the circle, the value of PI will remain constant.

In JavaScript, we can use Math.PI property to get the value of PI. This property returns the ratio of the circumference of a circle to its diameter, which is approximately equal to 3.14159. The Math.PI is a property of the Math object, not a function, so use this as a function will cause an error.

The value of PI is generally used in formulae. Using Math.PI property, we can easily calculate the area of a circle and can perform other calculations that require the value of PI.

Syntax

Let's see some illustrations of using the Math.PI property.

Example1

In this example, we are printing the value of the Math.PI property. Click the given button to get the value of PI.

Test it Now

Output

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

How to get the value of PI using JavaScript

Example2

In this example, we are calculating the area of the circle. The formula for finding the area is (π * r * r) that requires the value of PI. So, we are using Math.PI property to get the value of PI.

Here, the radius of the circle is 8.

Test it Now

Output

How to get the value of PI using JavaScript