totn JavaScript

JavaScript: Math.PI property

This JavaScript tutorial explains how to use the math property called Math.PI with syntax and examples.

Description

In JavaScript, Math.PI is a math property that is used to return the mathematical constant π (pi). Because Math.PI is a property of the Math object, it must be invoked through the placeholder object called Math.

Syntax

In JavaScript, the syntax for the Math.PI property is:

Math.PI;

Parameters or Arguments

There are no parameters or arguments for the Math.PI property.

Returns

The Math.PI property returns the mathematical constant π (pi) which has an approximate value of 3.141592653589793.

Note

  • The Math.PI property is a property of the Math object and not a math function. However, we have included the Math.PI property within our JS Math Functions section because you will most likely use this property in conjunction with the Math functions found in this section.

Example

Let's take a look at an example of how to use the Math.PI property in JavaScript.

For example:

console.log(Math.PI);

In this example, we have invoked the Math.PI property using the Math class.

We have written the output of the Math.PI property to the web browser console log, for demonstration purposes, to show what the Math.PI property returns.

The following will be output to the web browser console log:

3.141592653589793

In this example, the Math.PI property returned a value of 3.141592653589793 which is the value of the mathematical constant π or pi.