How to use Math.pow() function In Javascript
The Math. pow() method is used to power a number i.e., the value of the number raised to some exponent. In this case, we need to pass a (edge) as base and exponent is 3.
Syntax:
Math.pow(base, exponent)
Parameters:
- base: It is the base number that is to be raised.
- exponent: It is the value used to raise the base.
Example: Below is the function to find Volume of Cube using Math.pow() function.
let a = 5;
console.log('Volume = '+Math.pow(a,3));
Output:
Volume = 125
JavaScript Program to Find Volume of a Cube
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.
The Volume (V) of a Cube can be calculated using the given formula: Volume(V) = a * a * a
Where, a is the Edge of the Cube.
Example:
Input : 10
Output : Volume = 1000
Input : 5
Output : Volume = 125
Table of Content
- Using direct formulae
- Using Math.pow() function
- Using Exponentiation Operator
- Using ES6 arrow function