JavaScript Math.PI Constant

Beginner
5 min read
Updated: Nov 2026
3 examples
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.

JavaScript
Math.PI
UsageWhat 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
JavaScript
Math.PI

Parameters

None. Math.PI is a constant (a fixed value), not a function. Do not add parentheses.

Return Value

Return ValueDescription
NumberAbout 3.141592653589793.

JavaScript Examples

Example 1 — Read the Value of Math.PI

No parentheses are needed. Just write Math.PI.

JavaScript
console.log(Math.PI); // 3.141592653589793
console.log(Math.PI.toFixed(2)); // 3.14
console.log(typeof Math.PI); // number
Try It Yourself

How It Works

  1. Plain property. Math.PI is a value, so there are no parentheses.
  2. Long decimal. The full number has 16 digits.
  3. Short form. toFixed(2) gives "3.14" as text.
  4. 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.

JavaScript
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
Try It Yourself

How It Works

  1. Radius. The distance from the center to the edge is 5.
  2. Area. Math.PI * 5 * 5 is about 78.54.
  3. Circumference. 2 * Math.PI * 5 is about 31.42.
  4. 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.

JavaScript
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
Try It Yourself

How It Works

  1. Degrees to radians. Multiply by Math.PI / 180.
  2. 180 degrees. That is exactly Math.PI.
  3. 90 degrees. That is half of pi, about 1.5708.
  4. Back again. Multiply by 180 / Math.PI to return to degrees.

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

It is the value of pi, about 3.141592653589793.
No. Math.PI is a number, not a function. Write Math.PI, not Math.PI().
Use Math.PI * radius * radius, or Math.PI * radius ** 2.
Multiply by Math.PI / 180. For example, 180 degrees is Math.PI radians.
No. It is read-only. Trying to change it does nothing, or throws an error in strict mode.
All of them. It is part of the first JavaScript standard and works in every browser and in Node.js.

Next: SQRT1_2

Learn about square root of 1/2.

SQRT1_2 tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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