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 ![]() |
? WhatsApp is one of the most popular mobile messaging apps nowadays. It was developed by Jan Koum and Brian Acton, but now it is owned by Facebook. Recently, there are almost 1.5 million active users on it. As WhatsApp is a too popular chatting app, most...
7 min read
? JavaScript is a light-weight object-oriented programming language that is used by several websites for scripting the webpages. It is an interpreted, full-fledged programming language. JavaScript enables dynamic interactivity on websites when it is applied to an HTML document. JavaScript helps the users to build modern web...
3 min read
A 2D drawing context's translate() method is used. The canvas and its origin are moved by x and y units using the translate(x,y) method. Otherhand, The drawing position (0,0) on the canvas is remapped by the translate() method. The value is included in the x- and...
6 min read
The javascript prepend() method adds a set of array node objects or DOMString objects before the first child of an html parent node. There are two ways to use the javascript prepend method with the parent node. Using the prepend() method to prepend node Using the prepend()...
4 min read
The JavaScript change event is an event type that gets executed when the focus on an element is changed. The change event of JavaScript inherits all the methods and properties of the Event. Here, in this section, we will understand and implement the practical use of...
5 min read
Window.location is used to provide a Location object with details about the document's current location. This Location object reflects the location (URL) of the object it's linked to, i.e., it holds information about the current content location (host, href, etc.) JavaScript Location Object The window.location attribute represents...
8 min read
iousSibling Property in Javascript The iousSibling property serves to get the ious or earlier node of the given node as a Node object. If the given node is the first item in the list, then the node object shows null. The iousSibling property displays the element that...
5 min read
The focusout event of JavaScript is the event handler that executes when the element is just about to lose focus. Other than this, we have also learned about blur, which is also an event handler used in JavaScript. Both blur and focusout are the focus...
3 min read
In this article, we will explain about the javaScript and the ripple effect. After that, we will learn the various practical examples of ripple effects with the help of JavaScript. What do you mean by JavaScript? JavaScript is a client-side high-level, interpreted programming and scripting language used...
6 min read
? A WebSocket is a continuous two-way communication channel between clients and servers. The client could be any web browser, and the server could be any backend system. Using the HTTP request/response connections, the WebSocket can transmit any number of protocols and can provide server-to-client information...
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