How to use Exponentiation Operator In Javascript
Exponentiation operator is represented by “**” which is used to find the power of the first operator raised to the second operator. We need to pass edge (a) as the first operator and 3 as the second operator.
Syntax:
a ** 3
Example: Below is the function to find Volume of Cube using the Exponentiation operator.
let a = 5;
console.log('Volume = '+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
Contact Us