var val= Math.pow(4, 2); document.write(val);
- Here, we have created the variable “val”.
- If we want to find the square of 4, so here we use the Math.pow() method and pass 4 in first parameter value.
- Then we pass 2 in the second parameter value because here we find a square, so we put 2.
- 4 square is 16, the below output is displayed successfully 16.
If you want to find the cube value, you pass 3 as the second parameter value. Ex: Math.pow(2, 3) = 16