What’s the fastest way to JavaScript square a number?

What’s the fastest way to JavaScript square a number?

For example, given the number 61, which method performs best? Here are two approaches I have:

function squareIt(number) {
return Math.pow(number, 2);
}
function squareIt(number) {
return number * number;
}

Is there a more efficient method I should consider? I’m looking for the option that the compiler handles best on average, not a shortened version. I also noticed discussions suggesting that squaring a number is faster than multiplying two random numbers, but does this apply to n * n versus math.pow(n, 2)?

Hi,

This method is straightforward and generally the fastest.

function squareIt(number) {
return number * number;
}

This approach utilizes basic multiplication, which is usually optimized in JavaScript engines.