To get the value of pi in JavaScript, the easiest way is use the JavaScript math module constant pi. Math.PI returns the value 3.141592653589793.
console.log(Math.PI)
//Output:
3.141592653589793
In JavaScript, we can easily get the value of pi for use in trigonometry
with the JavaScript math module.
For example, let’s say we want to find the sine of a number. The JavaScript sin() function takes a number in radians and then finds the sine of the number.
To find the sine of a number, we can use pi to make our lives easy.
To get the value of pi in your JavaScript code, you just need access the ‘PI’ property as shown below.
console.log(Math.PI)
Then, if you want to use it like in our example with finding the sine of a number, you can use the pi constant in the following way.
console.log(Math.sin(Math.PI/3))
#Output:
0.8660254037844386
Hopefully this article has been helpful for you to understand how to find the value of pi from the JavaScript math module.