How to usethe Math Object in Javascript

In this approach, we are using the Math object is a built-in global object that provides various mathematical functions and constants, including operations like trigonometry, logarithms, and constants like π (pi).

Syntax:

 const piValue = Math.PI;

Example: here is the basic example of using math.object.

Javascript




const piValue = Math.PI;
console.log("π (pi) Value is :", piValue);


Output

π (pi) Value is : 3.141592653589793

JavaScript Program to Get the Value of PI

In this article, we will explore various ways to get the value of π in JavaScript. The value of π (pi) is a mathematical constant representing the ratio of a circle’s circumference to its diameter. It’s approximately 3.141592653589793 and is used in various mathematical and scientific calculations.

Table of Content

  • Using the Math Object
  • Using Math.atan()
  • Using for..of loop

We will explore all the above methods along with their basic implementation with the help of examples.

Similar Reads

Approach 1: Using the Math Object

...

Apporach 2: Using Math.atan()

In this approach, we are using the Math object is a built-in global object that provides various mathematical functions and constants, including operations like trigonometry, logarithms, and constants like π (pi)....

Approach 3: Using for..of loop

...