How to use Function In Javascript
We will create a function that will hold the formula by taking the edge of a cube (a) as a parameter. The function proceeds to calculate the Surface area of the Cube using the formula (6 * a * a). The calculated Surface Area is returned as the result of the function.
Syntax
function surfaceAreaCube(a) {
return 6 * a * a;
}
Example: Below is the function to find the Surface area of the Cube
function surfaceAreaCube(a) {
return (6 * a * a);
}
let a = 10;
console.log('Surface area = ' + surfaceAreaCube(a));
Output:
Surface area = 600
Surface area of Cube using JavaScript
A cube is a 3-dimensional box-like figure represented in the 3-dimensional plane that has six-shaped faces. It has length, width, and height of the same dimension. Three sides of a cube meet at the same vertex.
We can find the Surface area of Cube in JavaScript by using different ways including, the JavasScript function, Arrow function, and by using class.
Table of Content
- Using JavaScript Function
- Using Arrow function
- Using class