Computer >> Computer tutorials >  >> Programming >> Javascript

How to get the value of PI in JavaScript?


To get the value of PI in JavaScript, use the Math.PI property. It returns the ratio of the circumference of a circle to its diameter, which is approximately 3.14159.

Example

You can try to run the following code to get the value of PI in JavaScript −

<html>
   <head>
      <title>JavaScript Math PI Property</title>
   </head>
   <body>
      <script>
         var property_value = Math.PI
         document.write("Property Value: " + property_value);
      </script>
   </body>
</html>