Here is a small improvement I can suggest. First - start iterating from 0. Second - exit loop when the square of root candidate exceeds the number.

function squareroot(number) {
    for (var i = 0; i * i <= number; i++) {
        if (i * i === number)
            return i;
   }
   return number; // don't know if you should have this line in case nothing found
}

This algo will work in O(√number) time comparing to initial O(n) which is indeed performance improvement that you asked.

Edit #1

Just even more efficient solution would be to binary search the answer as @Spektre suggested. It is known that x2 is increasing function.

function squareroot(number) {
    var lo = 0, hi = number;
    while(lo <= hi) {
         var mid = Math.floor((lo + hi) / 2);
         if(mid * mid > number) hi = mid - 1;
         else lo = mid + 1;
    }
    return hi;
}

This algo has O(log(number)) running time complexity.

Answer from Ivan Gritsenko on Stack Overflow
🌐
W3Schools
w3schools.com › jsref › jsref_sqrt.asp
JavaScript Math sqrt() Method
❮ Previous JavaScript Math Object ... = Math.sqrt(64); let e = Math.sqrt(-9); Try it Yourself » · The Math.sqrt() method returns the square root of a number....
Discussions

JavaScript - Improving algorithm for finding square roots of perfect squares without Math.sqrt - Stack Overflow
I'm trying to learn algorithms and coding stuff by scratch. I wrote a function that will find square roots of square numbers only, but I need to know how to improve its performance and possibly ret... More on stackoverflow.com
🌐 stackoverflow.com
Is there a way to evaluate square root in HTML w/o Javascript?
Anything in “onclick” is JavaScript. HTML is markup and CSS is style; you can’t make a functional calculator without JavaScript. More on reddit.com
🌐 r/HTML
10
0
June 12, 2024
How to implement sqrt() in javascript.
Here's my implementation var math = { sqrt: function(x) { return Math.sqrt(x); } } Pretty sweet if I do say so myself. More on reddit.com
🌐 r/javascript
25
20
January 26, 2011
[AskJS] Why Math.sqrt is so slow in Firefox?
I guess Chromium is optimised to run Quake III but Firefox isn't. More on reddit.com
🌐 r/javascript
16
119
March 15, 2022
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Math › sqrt
JavaScript Math sqrt() - Calculate Square Root | Vultr Docs
September 27, 2024 - The Math.sqrt() function in JavaScript is a standard method used to calculate the square root of a number.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-program-to-find-the-square-root
JavaScript Program to Find the Square Root - GeeksforGeeks
July 23, 2025 - Example: In this example we will find the square root using JavaScript Math.sqrt() method.
🌐
p5.js
p5js.org › reference › p5 › sqrt
sqrt
A number's square root can be multiplied by itself to produce the original number. For example, sqrt(9) returns 3 because 3 × 3 = 9. sqrt() always returns a positive value.
Find elsewhere
🌐
CoreUI
coreui.io › answers › how-to-get-the-square-root-of-a-number-in-javascript
How to get the square root of a number in JavaScript · CoreUI
September 28, 2025 - The Math.sqrt() function returns the square root of a number, which is the value that when multiplied by itself equals the original number. In these examples, Math.sqrt(16) returns 4 because 4 × 4 = 16, and Math.sqrt(2.25) returns 1.5 because ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-math-sqrt-method
JavaScript Math sqrt() Method - GeeksforGeeks
July 15, 2024 - The JavaScript Math sqrt( ) Method in JavaScript is used to square the root of the number passed as a parameter to the function.
🌐
Programiz
programiz.com › javascript › examples › square-root
JavaScript Program to Find the Square Root
If 0 or a positive number is passed in the Math.sqrt() method, then the square root of that number is returned. If a negative number is passed, NaN is returned. If a string is passed, NaN is returned. ... Before we wrap up, let’s put your knowledge of JavaScript Program to Find the Square ...
🌐
WsCube Tech
wscubetech.com › resources › javascript › programs › square-root
JavaScript Program to Find the Square Root: With Examples
January 20, 2026 - Discover the easiest ways to find square roots in JavaScript, both with and without using built-in functions. Learn now!
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › SQRT2
Math.SQRT2 - JavaScript | MDN
July 10, 2025 - The Math.SQRT2 static data property represents the square root of 2, approximately 1.414.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › hypot
Math.hypot() - JavaScript | MDN
July 10, 2025 - The Math.hypot() static method returns the square root of the sum of squares of its arguments. That is,
🌐
TutorialsPoint
tutorialspoint.com › home › javascript › javascript math sqrt() function
JavaScript Math sqrt() Function
September 1, 2008 - This method returns the square root of the provided number. Following is the basic example of JavaScript Math.sqrt() method
🌐
Gitbook
baldur.gitbook.io › js › js-math › mathematical › math-sqrt-method
Math sqrt( ) Method | JS/TS
January 18, 2021 - We cannot provide a description for this page right now
🌐
W3Schools
www-db.deis.unibo.it › courses › TW › DOCS › w3schools › jsref › jsref_sqrt.asp.html
JavaScript sqrt() Method
Return the square root of different numbers: 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); The result of a,b,c,d, and e will be: 0 1 3 8 NaN Try it Yourself » · JavaScript Math Object · HTML, CSS, JavaScript, PHP, jQuery, Bootstrap and XML Certifications ·
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › WebAssembly › Reference › Numeric › Square_root
Square root - WebAssembly | MDN
April 9, 2025 - (module (import "console" "log" (func $log (param f32))) (func $main f32.const 2 ;; load a number onto the stack f32.sqrt ;; calculate the square root call $log ;; log the result ) (start $main) )
🌐
Stack Abuse
stackabuse.com › square-root-in-javascript
Square Root in JavaScript
April 6, 2023 - We can use the Math.sqrt() static function in JavaScript to calculate the square root of any number. This function can be used to calculate the square root of a positive number and an array with a single element.