To square a number in JavaScript do this:
Math.pow(number, 2)
.So, if your number is 5
, then you can square it like so:
const myNumber = 5;
const square = Math.pow(myNumber, 2); // 25
Another way
Another way is to multiply the number by itself using the *
operator:
const myNumber = 5;
const square = myNumber * myNumber; // 25