Math.PI

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Math.PI 静态数据属性表示圆的周长与直径的比例,其值约为 3.14159。

尝试一下

function calculateCircumference(radius) { return 2 * Math.PI * radius; } console.log(Math.PI); // Expected output: 3.141592653589793 console.log(calculateCircumference(10)); // Expected output: 62.83185307179586 

𝙼𝚊𝚝𝚑.𝙿𝙸=π3.14159\mathtt{Math.PI} = \pi \approx 3.14159
Math.PI 的属性特性
可写
可枚举
可配置

描述

由于 PIMath 的静态属性,因此应始终使用 Math.PI,而不是作为你创建的 Math 对象的属性(Math 不是构造函数)。

示例

使用 Math.PI

以下函数使用 Math.PI 来计算给定半径的圆周长。

js
function calculateCircumference(radius) { return Math.PI * (radius + radius); } calculateCircumference(1); // 6.283185307179586 

规范

Specification
ECMAScript® 2026 Language Specification
# sec-math.pi

浏览器兼容性

参见