Home JavaScript Math Methods PI JavaScript Math.PI Constant Definition Math.PI is a built-in constant that holds the value of pi, about 3.141592653589793. Pi is the ratio of a circle's circumference to its diameter. You read it as a property. You do not call it.
Read the value, use it in your math, and check the examples below for common patterns.
Syntax Read the constant. Start with this line.
Usage What it does Math.PIRead the value of pi.
Built into JavaScript. Read Math.PI directly from the Math object — no parentheses and no import required.
Library declarations Parameters None. Math.PI is a constant (a fixed value), not a function. Do not add parentheses.
Return Value Return Value Description Number About 3.141592653589793.
Important
Math.PI is read-only . Write Math.PI, not Math.PI(). It is a rounded number, so results like Math.sin(Math.PI) have tiny errors. JavaScript angles use radians, and Math.PI radians is 180 degrees.
JavaScript Examples 1. Read the value 2. Circle area 3. Degrees and radians Example 1 — Read the Value of Math.PI No parentheses are needed. Just write Math.PI.
console.log(Math.PI); // 3.141592653589793
console.log(Math.PI.toFixed(2)); // 3.14
console.log(typeof Math.PI); // number 3.141592653589793
3.14
number How It Works Plain property. Math.PI is a value, so there are no parentheses.Long decimal. The full number has 16 digits.Short form. toFixed(2) gives "3.14" as text.Type. typeof says it is a number.Example 2 — Area and Circumference of a Circle Use a radius of 5. The area is π × r × r and the circumference is 2 × π × r.
const radius = 5;
const area = Math.PI * radius * radius;
const circumference = 2 * Math.PI * radius;
console.log(area.toFixed(2)); // 78.54
console.log(circumference.toFixed(2)); // 31.42 How It Works Radius. The distance from the center to the edge is 5.Area. Math.PI * 5 * 5 is about 78.54.Circumference. 2 * Math.PI * 5 is about 31.42.Rounding. toFixed(2) keeps two decimals.Example 3 — Convert Degrees and Radians Half a circle is 180 degrees, which is Math.PI radians. Use this to switch between the two.
function toRadians(degrees) {
return degrees * Math.PI / 180;
}
function toDegrees(radians) {
return radians * 180 / Math.PI;
}
console.log(toRadians(180)); // 3.141592653589793
console.log(toRadians(90)); // 1.5707963267948966
console.log(toDegrees(Math.PI / 2)); // 90 3.141592653589793
1.5707963267948966
90 How It Works Degrees to radians. Multiply by Math.PI / 180.180 degrees. That is exactly Math.PI.90 degrees. That is half of pi, about 1.5708.Back again. Multiply by 180 / Math.PI to return to degrees.Compatibility
Browser & Runtime Support Math.PI is part of the first JavaScript standard (ES1 ) and is Baseline Widely available in every browser and in Node.js.
✓ Baseline · ES1
Math.PI A long-standing constant. It works in Chrome, Firefox, Safari, Edge, Internet Explorer and Node.js.
99% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support Math.PI Excellent
Bottom line: Use Math.PI anywhere. It works in all browsers.
Frequently Asked Questions What is Math.PI in JavaScript? It is the value of pi, about 3.141592653589793.
Do I use parentheses with Math.PI? No. Math.PI is a number, not a function. Write Math.PI, not Math.PI().
How do I find the area of a circle? Use Math.PI * radius * radius, or Math.PI * radius ** 2.
How do I convert degrees to radians? Multiply by Math.PI / 180. For example, 180 degrees is Math.PI radians.
Can I change the value of Math.PI? No. It is read-only. Trying to change it does nothing, or throws an error in strict mode.
Which browsers support Math.PI? All of them. It is part of the first JavaScript standard and works in every browser and in Node.js.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
9 people found this page helpful
Helpful Share Copy link Suggestion