JavaScript Tutorial JavaScript References

JavaScript - Math.PI Property



The JavaScript Math.PI property is the ratio of the a circle's circumference to its diameter. It is approximately 3.14159.

Syntax

Math.PI

Example:

The example below shows the usage of Math.PI property.

var txt;
var pi = Math.PI;

txt = "pi = " + pi + "<br>";
txt = txt + "Math.sin(pi/2) = " + Math.sin(pi/2) + "<br>";
txt = txt + "Math.cos(pi/2) = " + Math.cos(pi/2) + "<br>";
txt = txt + "Math.tan(pi/2) = " + Math.tan(pi/2) + "<br><br>";

txt = txt + "Radius of a circle = 10 <br>";
txt = txt + "Circumference of the circle = " + (2 * pi * 10) + "<br>";
txt = txt + "Area of the circle = " + (pi * 10 * 10) + "<br>";

The output (value of txt) after running above script will be:

pi = 3.141592653589793
Math.sin(pi/2) = 1
Math.cos(pi/2) = 6.123233995736766e-17
Math.tan(pi/2) = 16331239353195370

Radius of a circle = 10
Circumference of the circle = 62.83185307179586
Area of the circle = 314.1592653589793

❮ JavaScript - Math Object

5