How to use Destructuring Assignment and Spread Operator In Javascript
In this approach, we are using the destructuring assignment and the spread operator to encapsulate the sum of the squares of radius and height within an array, allowing Math.sqrt to extract the value for calculating the surface area of the cone.
Syntax:
let [, value] = [...[expression]];
Example: The below uses Destructuring Assignment and Spread Operator to find the Surface area of a Cone.
let r = 5;
let h = 10;
let res = Math.PI * r * (r + Math.sqrt([...[r*r + h*h]]));
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
Contact Us