Note: Questions like this change over time as browser engines change how their optimizations work. For a recent look comparing:

Math.pow(x1, 2)
x1 * x1
x1 ** 2                  // ES6 syntax

See this revised performance test and run it in the browsers you care about: https://jsperf.com/math-pow-vs-simple-multiplication/32.

As of April 2020, Chrome, Edge and Firefox show less than 1% difference between all three of the above methods.

If the jsperf link is not working (it seems to be occasionally down), then you can try this perf.link test case.

Original Answer from 2014:

All performance questions should be answered by measurement because specifics of the browser implementation and the particular scenario you care about are often what determine the outcome (thus a theoretical discussion is not always right).

In this case, performance varies greatly by browser implementation. Here are are results from a number of different browsers in this jsperf test: http://jsperf.com/math-pow-vs-simple-multiplication/10 which compares:

Math.pow(x1, 2)
x1 * x1

Longer bars are faster (greater ops/sec). You can see that Firefox optimizes both operations to be pretty much the same. In other browsers, the multiplication is significantly faster. IE is both the slowest and shows the greatest percentage difference between the two methods. Firefox is the fastest and shows the least difference between the two.

Answer from jfriend00 on Stack Overflow
🌐
W3Schools
w3schools.com › jsref › jsref_sqrt.asp
JavaScript Math sqrt() Method
The Math.sqrt() method returns the square root of a number. The Math.cbrt() Method The Math.SQRT2 Property The Math.SQRT1_2 Property ... Math. is an ECMAScript1 (JavaScript 1997) feature.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › sqrt
Math.sqrt() - JavaScript | MDN
The square root of x, a nonnegative number. If x < 0, returns NaN. Because sqrt() is a static method of Math, you always use it as Math.sqrt(), rather than as a method of a Math object you created (Math is not a constructor). ... Math.sqrt(-1); // NaN Math.sqrt(-0); // -0 Math.sqrt(0); // 0 ...
Top answer
1 of 3
105

Note: Questions like this change over time as browser engines change how their optimizations work. For a recent look comparing:

Math.pow(x1, 2)
x1 * x1
x1 ** 2                  // ES6 syntax

See this revised performance test and run it in the browsers you care about: https://jsperf.com/math-pow-vs-simple-multiplication/32.

As of April 2020, Chrome, Edge and Firefox show less than 1% difference between all three of the above methods.

If the jsperf link is not working (it seems to be occasionally down), then you can try this perf.link test case.

Original Answer from 2014:

All performance questions should be answered by measurement because specifics of the browser implementation and the particular scenario you care about are often what determine the outcome (thus a theoretical discussion is not always right).

In this case, performance varies greatly by browser implementation. Here are are results from a number of different browsers in this jsperf test: http://jsperf.com/math-pow-vs-simple-multiplication/10 which compares:

Math.pow(x1, 2)
x1 * x1

Longer bars are faster (greater ops/sec). You can see that Firefox optimizes both operations to be pretty much the same. In other browsers, the multiplication is significantly faster. IE is both the slowest and shows the greatest percentage difference between the two methods. Firefox is the fastest and shows the least difference between the two.

2 of 3
34

In ES6 you can do the following with Exponentiation (x ** y), which produces the same result as Math.pow(x,y):

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

console.log(squareIt(5));

or you can use a JavaScript library called BigInteger.js for the purpose.

alert(bigInt(5).square());
<script src="https://cdnjs.cloudflare.com/ajax/libs/big-integer/1.6.40/BigInteger.min.js"></script>

🌐
Math.js
mathjs.org › docs › reference › functions › square.html
math.js | an extensive math library for JavaScript and Node.js
math.square(2) // returns number 4 math.square(3) // returns number 9 math.pow(3, 2) // returns number 9 math.multiply(3, 3) // returns number 9 math.map([1, 2, 3, 4], math.square) // returns Array [1, 4, 9, 16]
🌐
p5.js
p5js.org › reference › p5 › square
square
A square is a four-sided shape defined by the x, y, and s parameters. x and y set the location of its top-left corner. s sets its width and height. Every angle in the square measures 90˚ and all its sides are the same length.
🌐
Medium
rustcodeweb.medium.com › the-simple-trick-to-squaring-numbers-in-javascript-c1ce2eaca1f8
The Simple Trick to Squaring Numbers in JavaScript! | by RustcodeWeb | Medium
August 18, 2024 - Math.pow(number, 2) raises the number to the power of 2, effectively squaring it. The exponentiation operator (**) is a more recent addition to JavaScript, providing a concise syntax for exponentiation.
🌐
W3Schools
w3schools.com › jsref › jsref_pow.asp
JavaScript Math pow() Method
Math.pow() is an ECMAScript1 (JavaScript 1997) feature. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
🌐
Altcademy
altcademy.com › blog › how-to-square-a-number-in-javascript
How to square a number in JavaScript
June 9, 2023 - In this example, we first declare a variable number and assign it the value 5. Then, we use the Math.pow() method to calculate the square of the number and store the result in a variable called square.
Find elsewhere
🌐
W3Schools
w3schools.com › JSREF › jsref_sqrt2.asp
JavaScript Math SQRT2 Property
The Math.SQRT2 property returns the square root of 2. The Math.SQRT2 property returns approximately 1.414. The Math.sqrt() Method The Math.cbrt() Method The Math.SQRT1_2 Property ...
🌐
Medium
medium.com › @cyberbotmachines › how-to-square-a-number-in-javascript-solved-6de86faebf08
How To Square A Number In JavaScript — [SOLVED] - CyberBotMachines - Medium
November 28, 2023 - Then you use one of two methods in JavaScript: 1) Math.pow(3, 2) — this gives you 9 2) 3 ** 2 — this also gives you 9 · Also notice that you don’t have to only take the 2nd power of the number, you can do more, for example take 3rd power: Math.pow(3, 3) — 3 x 3 x 3 = 27 3 ** 3 — this is also 27 · And that’s all there is to squaring the number in JavaScript.
🌐
Codecademy
codecademy.com › forum_questions › 4fc0326bd12f0a0003005677
I don't get how the square function works | Codecademy
The square function is basically telling the computer to multiply (“this number” by “the same number”). Now when we want to use the square function first we have to declare it with: var square=function(x) ... So we tell the computer ...
🌐
sebhastian
sebhastian.com › javascript-square
JavaScript - how to square a number in three easy ways | sebhastian
May 23, 2021 - And that’s how you find the square of a number using Math.pow() method. Let’s see how you can use the exponentiation operator next. JavaScript provides you with the exponentiation operator marked by two asterisk symbols (**) like this:
🌐
Programiz
programiz.com › javascript › examples › square-root
JavaScript Program to Find the Square Root
// take the input from the user const number = prompt('Enter the number: '); const result = Math.sqrt(number); console.log(`The square root of ${number} is ${result}`); ... const number1 = 2.25; const number2 = -4; const number3 = 'hello'; const result1 = Math.sqrt(number1); const result2 = ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-program-to-find-the-area-of-a-square
JavaScript Program to Find the Area of a Square - GeeksforGeeks
August 5, 2025 - Here, an arrow function is used to calculate the area of a square. Arrow functions are a concise way to write functions in JavaScript.
🌐
W3Schools
www-db.deis.unibo.it › courses › TW › DOCS › w3schools › jsref › jsref_sqrt.asp.html
JavaScript sqrt() Method
The sqrt() method returns the square root of a number. ... var a = Math.sqrt(0); var b = Math.sqrt(1); var c = Math.sqrt(9); var d = Math.sqrt(64); var e = Math.sqrt(-9); ... Color Converter Google Maps Animated Buttons Modal Boxes Modal Images Tooltips Loaders JS Animations Progress Bars Dropdowns ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › pow
Math.pow() - JavaScript | MDN
In addition, the behavior where base is 1 and exponent is non-finite (±Infinity or NaN) is different from IEEE 754, which specifies that the result should be 1, whereas JavaScript returns NaN to preserve backward compatibility with its original behavior. Because pow() is a static method of Math, use it as Math.pow(), rather than as a method of a Math object you created (Math is not a constructor). ... // Basic cases Math.pow(7, 2); // 49 Math.pow(7, 3); // 343 Math.pow(2, 10); // 1024 // Fractional exponents Math.pow(4, 0.5); // 2 (square root of 4) Math.pow(8, 1 / 3); // 2 (cube root of 8) M
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-program-to-check-whether-a-number-is-perfect-square
JavaScript Program to Check Whether a Number is Perfect Square - GeeksforGeeks
July 23, 2025 - The number that results from squaring another integer is called a perfect square. A perfect square is a number that can be expressed as the product of an integer with itself. There are several ways available in JavaScript to check whether a ...
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Math › sqrt
JavaScript Math sqrt() - Calculate Square Root | Vultr Docs
September 27, 2024 - In this article, you will learn how to use the Math.sqrt() function effectively in JavaScript. You will explore various examples that demonstrate how to calculate square root in javascript, handle negative numbers, and integrate this function ...