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
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>

๐ŸŒ
Programiz
programiz.com โ€บ javascript โ€บ examples โ€บ square-root
JavaScript Program to Find the Square Root
const number1 = 2.25; const number2 = -4; const number3 = 'hello'; const result1 = Math.sqrt(number1); const result2 = Math.sqrt(number2); const result3 = Math.sqrt(number3); console.log(`The square root of ${number1} is ${result1}`); console.log(`The square root of ${number2} is ${result2}`); ...
๐ŸŒ
Altcademy
altcademy.com โ€บ blog โ€บ how-to-square-a-number-in-javascript
How to square a number in JavaScript - Altcademy.com
June 9, 2023 - In this example, we define a function called square that takes a single parameter number and returns its square. We then declare a variable number and assign it the value 5. We call the square function with the number as an argument and store ...
๐ŸŒ
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 - To square a number, you raise it to the power of 2. // Squaring a number using Math.pow() const number = 5; const squared = Math.pow(number, 2); console.log(squared); // Output: 25
๐ŸŒ
Math.js
mathjs.org โ€บ docs โ€บ reference โ€บ functions โ€บ square.html
math.js | an extensive math library for JavaScript and Node.js
Compute the square of a value, x * x. To avoid confusion with multiplying a square matrix by itself, this function does not apply to matrices. If you wish to square every element of a matrix, see the examples.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ javascript โ€บ javascript square a number
How to Square a Number in JavaScript | Delft Stack
February 2, 2024 - In this example, we declare a constant variable named number and assign it the value 5. Then, we square the number 5 by using Math.pow(number, 2). The result, stored in the squared variable, is 25, which is the square of 5. Another way to square ...
๐ŸŒ
Enterprise DNA
blog.enterprisedna.co โ€บ how-to-square-a-number-in-javascript
How to Square a Number in JavaScript: 3 Quick Explained โ€“ Master Data Skills + AI
Keep reading to learn more about ... calculates the area of a square with sides of the given value. For example, if you have a number 5, squaring it will give you 25 (5 ร— 5 = 25)....
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ javascript โ€บ standard-library โ€บ Math โ€บ sqrt
JavaScript Math sqrt() - Calculate Square Root | Vultr Docs
September 27, 2024 - This code calculates the square root of 9, which is 3. Pass a non-numeric value or undefined to Math.sqrt() to see the result. Note that JavaScript handles these gracefully, turning them into NaN (Not a Number) or using type coercion if possible.
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
Team Treehouse
teamtreehouse.com โ€บ community โ€บ what-is-the-best-way-to-square-a-number-in-javascript
What is the best way to square a number in JavaScript? (Example) | Treehouse Community
May 16, 2016 - Michael Lowe is having issues with: Let's say I want to find 4 squared, i.e. 4^2 or 4 to the power of 2. Right now I have this: var x = 5; var x_squared = M...
๐ŸŒ
Sabe
sabe.io โ€บ blog โ€บ javascript-square-number
How to Square a Number in JavaScript - Sabe.io
March 4, 2022 - In this post, we explored the three best ways to square a number in JavaScript, using the Math.pow(), **, and a custom helper square() function.
๐ŸŒ
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 ... 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...
๐ŸŒ
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 - There are several ways available in JavaScript to check whether a number is a perfect square or not which are as follows: ... The simplest approach to checking whether a number is a perfect square is to use the Math.sqrt() function.
๐ŸŒ
Quora
quora.com โ€บ How-do-I-write-a-for-loop-to-square-the-numbers-from-1-10-in-JavaScript
How to write a for loop to square the numbers from 1-10 in JavaScript - Quora
And thatโ€™s how you square the topic variable via the clearest, least ambiguous string interpolation. ... It all on one line. And still intuitive and clear. And if you wanted to, you could have written it like this: ... Raku has the advantages of Haskell, Lisp, Swift and Perl all combined in one place. Programming will become fun again. ... How do I code in JavaScript that will let the user enter 15 entries of any number and then the total sum of all odd numbers entered will be displayed using loop?
๐ŸŒ
p5.js
p5js.org โ€บ reference โ€บ p5 โ€บ square
square
The version of square() with four parameters creates a rounded square.
๐ŸŒ
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 - Below are the methods by which we can find the area of a square in JavaScript: Table of Content ยท Using custom function ยท Using an Arrow Function ยท Using Math.pow() function ยท Using Object Literal Property Value Shorthand ยท In this approach, ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ p5-js-square-function
p5.js square() Function - GeeksforGeeks
July 12, 2025 - function setup() { // Create Canvas of given size createCanvas(300, 300); } function draw() { background(220); // Use color() function let c = color('green'); // Use fill() function to fill color fill(c); // Draw a square square(50, 50, 200); } ...