Math.PI
Math.PI
The ratio of the circumference of a circle to its diameter, π ≈ 3.141592653589793. Trigonometric functions (Math.sin(), Math.cos()) work in radians, so π is also used to convert from degrees.
Examples
console.log(Math.PI);
const r = 5;
console.log('Circumference:', (2 * Math.PI * r).toFixed(2), 'Area:', (Math.PI * r ** 2).toFixed(2));
const toRadians = (degrees) => (degrees * Math.PI) / 180;
console.log(Math.sin(toRadians(30)).toFixed(4), Math.cos(toRadians(60)).toFixed(4));
Output:
3.141592653589793 Circumference: 31.42 Area: 78.54 0.5000 0.5000
Things to watch out for
- The results of trigonometric functions are inexact in the last places (
Math.sin(Math.PI)is not exactly 0) – round them for output.
Browser support
Baseline – widely available: works in all major browsers and has for a long time (since 2015 at the latest). Since version: Chrome 1, Firefox 1, Safari 1; Node.js 0.10.0. As of October 2026 (MDN browser-compat-data).
Related:
Math.pow()
Math.hypot()