The Math.PI
property in JavaScript represents the mathematical constant π (pi), which is approximately equal to 3.14159. You can use this property in your JavaScript code just like any other variable. Here’s an example:
console.log("The value of pi is: " + Math.PI);
You can also use the Math.PI
property in mathematical expressions, such as calculating the area of a circle:
let radius = 5;
let area = Math.PI * (radius * radius);
console.log("The area of a circle with radius " + radius + " is " + area);
In this example, we first declare a variable radius
with a value of 5. Then, we use the Math.PI
property in an expression to calculate the area of a circle with that radius, and finally, we log the result to the console.
+ There are no comments
Add yours