Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Math.PI

The constant π — the ratio of a circle's circumference to its diameter.

Available since: ES1

Syntax

Math.PI

Return value

numberThe number π, about 3.14159.

Examples

The value of the constant:

console.log(Math.PI);

Output:

3.141592653589793

The area of a circle with radius 2:

const radius = 2;
 
console.log((Math.PI * radius ** 2).toFixed(2));

Output:

12.57

Notes

Math has other constants too: Math.E (the number e), Math.SQRT2 (the square root of two). They cannot be changed.

See also

In the tutorial

  • Numbers — Numbers in JavaScript — integers and fractions, rounding, the Math object, toFixed and the special values Infinity and NaN.

Thanks for reading!

Donate to the site — we work hard for you.