The JavaScript Math PI property
In JavaScript, the mathematical constant PI is stored in the Math object’s static property:
console.log(Math.PI);
// returns 3.141592653589793
You can use the value of Math.PI to find the Diameter when you know the Circumference:
// Diameter = Circumference / π
let circumference = 20
let diameter = circumference / Math.PI
You can find the Circumference by multiplying the PI with the Diameter:
// Circumference = π X Diameter
let diameter = 9
let circumference = Math.PI * diameter
Finally, you can calculate the Radius of a circle if you know the Circumference:
// Radius = Circumference X 2π
let circumference = 17;
let radius = circumference * (2 * Math.PI)
More JavaScript tutorials
See allJavaScript
Sort Keys in Map Using JavaScript
Dec 11, 2023
JavaScript
Get Element by Data Attribute Using JavaScript
Dec 8, 2023
JavaScript
Convert Milliseconds to Hours Minutes Seconds in JavaScript
Dec 6, 2023
JavaScript
JavaScript Get the Index of Max Value in Array
Nov 16, 2023
JavaScript
JavaScript Check if Value is an Object
Nov 15, 2023