You are currently viewing How to Square in JavaScript

How to Square in JavaScript

How to Square in JavaScript

In this article, we will see how to find square value in javascript. To find the square of a number, we need to use JavaScript pow() method. It is used to find the square values of numbers. We must pass two parameter values inside the method, one is the number and the other is a number of times to be multiplied.


var val= Math.pow(4, 2);


Output:  16

  1. Here, we have created the variable “val”.
  2. If we want to find the square of 4, so here we use the Math.pow() method and pass 4 in first parameter value.
  3. Then we pass 2 in the second parameter value because here we find a square, so we put 2.
  4. 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

Leave a Reply