JavaScript Program to Get the Value of PI Last Updated : 10 Oct, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 ContentUsing the Math ObjectUsing Math.atan()Using for..of loopWe will explore all the above methods along with their basic implementation with the help of examples. Approach 1: Using the Math ObjectIn 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 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); Outputvalue of π is : 3.141592653589793 Approach 3: Using for..of loopIn this approach, we use a for...of loop with an iterable sequence generated by Array(iterations).keys() to iteratively compute π by alternating fractions, enhancing readability while maintaining the original logic for increased accuracy. Syntax: for ( variable of iterableObjectName) { ...};Example: In this example we are using above explained approach. JavaScript function calculatePi(iterations) { let pi = 0; let sign = 1; for (let i of Array(iterations).keys()) { pi += (4 / (2 * i + 1)) * sign; sign *= -1; } return pi; } // Increase the number of iterations // for more accuracy const pi = calculatePi(1000000); console.log(pi); Output3.1415916535897743 Comment More infoAdvertise with us Next Article JavaScript Program to Find the Tangent of given Radian Value H hardikchouhan1901 Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League JavaScript-Methods JavaScript-Program Geeks Premier League 2023 +2 More Similar Reads JavaScript Program to Find the Volume of Cylinder We are going to see JavaScript Program to Find the Volume of Cylinder. We use direct formula to calculate volume of cylinder. A cylinder is a three-dimensional geometric shape that consists of two parallel circular bases connected by a curved surface. Formula usedV = Ïr2hwhere:V is volume of cylinde 1 min read JavaScript Program to Find the Tangent of given Radian Value Given a radian value, our task is to find a tangent using JavaScript. Tangent (tan) is a trigonometric function which is the ratio of the length of the side opposite to an angle to the length of the adjacent side in a right triangle. Example: Input: 45 degrees Output: 1Below are the approaches to fi 2 min read JavaScript program to find volume of cylinder To calculate the JavaScript Program to Find the Volume of the Cylinder. We use the direct formula to calculate the volume of the cylinder. A cylinder is a three-dimensional geometric shape that consists of two parallel circular bases connected by a curved surface. Example: V = Ïr^2hwhere,Ï is consta 2 min read JavaScript Program to Find Area of semi-circle Given the radius, our task is to find an area of a semi-circle in JavaScript. A semi-circle is a two-dimensional geometric shape that represents half of a circle. The area of a semi-circle can be calculated by squaring the radius of the semi-circle, then multiplying it by Ï and dividing by 2. Exampl 2 min read JavaScript Programs JavaScript Programs contains a list of articles based on programming. This article contains a wide collection of programming articles based on Numbers, Maths, Arrays, Strings, etc., that are mostly asked in interviews.Table of ContentJavaScript Basic ProgramsJavaScript Number ProgramsJavaScript Math 13 min read JavaScript Program to Convert Radians to Degree Radians and degrees are units of angular measurement used extensively in mathematics, physics, and engineering. Converting radians to degrees is a common operation in trigonometry and other mathematical calculations. Example:// Formula to convert radian into degree: degrees = radians à (180/Ï)Where: 2 min read Like