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 2015年7月.
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
値
Math.PI のプロパティ属性 | |
---|---|
書込可能 | 不可 |
列挙可能 | 不可 |
設定可能 | 不可 |
解説
PI
は Math
オブジェクトの静的プロパティなので、 Math
オブジェクトを生成してプロパティとして使用するのではなく、常に Math.PI
として使用するようにしてください (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> |
ブラウザーの互換性
Loading…