Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
Why MDN recommends += instead of the concat() method?

According to this MDN, it seems += is preferred over concat() for performance issues. So I use the following sample code to test.

var str = "";
var startTime = performance.now()
for(var i=0; i<10000000; i++) {
   str = str.concat(i);
}
var endTime = performance.now()
console.log(`concat took ${endTime - startTime} ms`)

str = "";
startTime = performance.now()
for(var i=0; i<10000000; i++) {
   str += i;
}
endTime = performance.now()
console.log(`+= took ${endTime - startTime} ms`)

But I don't see a significant difference until I increase the loop to 10,000,000 times. Here are some outputs I obtains when running on Chrome.

concat took 3067.600000023842 ms
+= took 2799 ms
concat took 2751.5 ms
+= took 2280.199999988079 ms
concat took 2865.699999988079 ms
+= took 1857.5999999642372 ms
concat took 2909.7000000476837 ms
+= took 2183.599999964237 ms

If you compare += and StringBuilder.append() with Java, you will observe a huge difference (e.g., 3 ms vs. 3000 ms) even testing on a loop of 10000 times.

So in which case can I observe a significant difference between += and concat() on JavaScript?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!