How to get the value of PI using JavaScript?17 Mar 2025 | 2 min read PI is a mathematical constant. The lowercase Greek letter π represents the symbol PI. It is an acronym of the periphery. PI can be defined as the circumference (C) of a circle divided by its diameter (d). It means that for any size of the circle, the value of PI will remain constant. In JavaScript, we can use Math.PI property to get the value of PI. This property returns the ratio of the circumference of a circle to its diameter, which is approximately equal to 3.14159. The Math.PI is a property of the Math object, not a function, so use this as a function will cause an error. The value of PI is generally used in formulae. Using Math.PI property, we can easily calculate the area of a circle and can perform other calculations that require the value of PI. SyntaxLet's see some illustrations of using the Math.PI property. Example1In this example, we are printing the value of the Math.PI property. Click the given button to get the value of PI. Output After the execution of above code and after clicking the given button the output will be - ![]() Example2In this example, we are calculating the area of the circle. The formula for finding the area is (π * r * r) that requires the value of PI. So, we are using Math.PI property to get the value of PI. Here, the radius of the circle is 8. Output ![]() |
Concept Design patterns can be termed as well-documented solutions to the most commonly occurring problems in software engineering. It turns quite hectic for developers to bang out their heads on the problem that someone else has already solved. Every developer aspires to write industrial-level code that...
9 min read
Unary operators in JavaScript are unique operators that consider a single input and carry out all possible operations. The Unary plus, unary minus, prefix increments, postfix increments, postfix decrements, and prefix decrements are examples of these operators. These operators are either put before or after the...
8 min read
JavaScript does not offer any specific in-built function to traverse the array elements/objects. You can traverse an array simply using for loop or directly by element index. An array contains multiple elements of the same type, which can be traverse using for loop. In this chapter,...
7 min read
Keep in mind that this is just the beginning. Try out these six backend projects, make a note of your challenges, and spend some time studying any challenging ideas. These six backend projects will allow you to strengthen your project portfolio while also identifying your...
4 min read
What is Underscore.js? Underscore.js is the library in JavaScript which has a lot of functions like map, filter, chain, etc., and these functions are applied directly on the objects or arrays. _.filter() function The _.filter() function is used to check and filter those elements which satisfy some specific...
4 min read
? The Promise in JavaScript may look quite complicated to understand at first sight, but in reality, it is quite simple and is not rocket science. In JavaScript, a promise is just like a promise that you make in real life to show that you are...
4 min read
The Element interface's insertAdjacentHTML() method converts the given text to HTML or XML and puts the generated nodes into the DOM tree at a predetermined point. To insert text as an HTML file at a certain point in the DOM, use the insertAdjacentHTML() method. The text...
4 min read
The ability to track DOM tree modifications is provided via the MutationObserver interface. It is intended to take the place of the ious Mutation Events functionality, which was included in the DOM3 Events definition. The DOM can often change in complex web projects. Because of this,...
7 min read
The output of raising a first input value to the power of the second input value is returned by the exponentiation (**) operator. It is the same as Math.pow(), except that it also accepts BigInts as operands. The javascript exponentiation operator is used to calculate the...
5 min read
JavaScript provides an efficient garbage collection for memory management. JavaScript automatically supports memory management and is invisible to us. When we create new objects, functions, primitives and variables, all these programming elements take memory. How does JavaScript manage these elements and cleans them? In this section,...
8 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India