How to use Math.pow In Javascript
In this approach, we are using the Math.pow function for exponentiation, applying it to the expression (r * r + h * h) to find the square root. The calculated result is then used in the formula π * r * (r + √(r² + h²)), with the final surface area displayed with two decimal places using toFixed.
Syntax:
Math.pow(base, exponent);
Example: The below uses Math.pow to find the Surface area of a Cone.
let r = 5;
let h = 10;
let res = Math.PI * r * (r + Math.pow((r * r + h * h), 0.5));
console.log(res.toFixed(2));
Output
254.16
JavaScript Program to Find Surface Area of a Cone
Mathematically, the Surface area of the Cone can be calculated using the formula: area = pi * r * s + pi * r^2, Where r is the radius of the circular base, and s is the slant height of the cone. We will calculate the Surface Area of a Cone programmatically using JavaScript.
These are the following methods:
Table of Content
- Using Destructuring Assignment and Spread Operator
- Using Arithmetic Operations
- Using Math.pow