Apporach 2: Using Math.atan()
Javascript Math.atan( ) method is used to return the arctangent of a number in radians. The Math.atan() method returns a numeric value between -pi/2 and pi/2 radians.
Syntax:
Math.atan(value)
Example: In this example we are using the above-explained method.
Javascript
const val = 4 * (Math.atan(1)); console.log( "value of π is :" , val); |
Output
value of π 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.