Get the Value of PI with JavaScript

02/06/2022

Contents

In this article, you will learn how to get the value of PI with JavaScript.

The Math.PI property

The Math.PI property returns the ratio of the circumference of a circle to its diameter.

The syntax is below.

Math.PI

console.log(Math.PI);
// expected output: 3.141592653589793

Sample Code

Below is a sample code to calculate the area of ​​a circle.

function calculateCircleArea(radius) {
  return radius * radius * Math.PI;
}

console.log(calculateCircleArea(10));
// expected output: 314.1592653589793