MDN has the following to say about string.concat():

It is strongly recommended to use the string concatenation operators (+, +=) instead of this method for perfomance reasons

Also see the link by @Bergi.

Answer from laktak on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › concat
String.prototype.concat() - JavaScript | MDN
The concat() method is very similar to the addition/string concatenation operators (+, +=), except that concat() coerces its arguments directly to strings, while addition coerces its operands to primitives first.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-string-concatenation
How JavaScript String Concatenation Works – the "+" Operator vs the "+=" Operator
September 7, 2023 - This method is very handy. When using it, we append separate strings in separate lines. Let me give you an example again. I will use a variable named fullName like earlier, but instead of using the + operator to concatenate strings like earlier, I will use +=:
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › Strings
Handling text — strings in JavaScript - Learn web development | MDN
You might expect this to return an error, but it works just fine. How numbers should be displayed as strings is fairly well-defined, so the browser automatically converts the number to a string and concatenates the two strings.
Top answer
1 of 4
73

Consider this piece of JavaScript code:

var a = 10;
var b = 20;
console.log('result is ' + a + b);

This will log

result is 1020

Which most likely is not what was intended, and can be a hard to track bug.

2 of 4
49

When you say "bad" do you mean "incorrect" or do you mean "slow"? The argument about using mathematical operators to do string concatenation is arguably an "incorrect" argument, but there's also an argument to be made that using + to do a lot of string concatenation can be very slow.

We're not talking about "Hello" + number when we talk about performance, we're talking about building up a relatively large string by repeatedly appending to it in a loop.

var combined = "";
for (var i = 0; i < 1000000; i++) {
    combined = combined + "hello ";
}

In JavaScript (and C# for that matter) strings are immutable. They can never be changed, only replaced with other strings. You're probably aware that combined + "hello " doesn't directly modify the combined variable - the operation creates a new string that is the result of concatenating the two strings together, but you must then assign that new string to the combined variable if you want it to be changed.

So what this loop is doing is creating a million different string objects, and throwing away 999,999 of them. Creating that many strings that are continually growing in size is not fast, and now the garbage collector has a lot of work to do to clean up after this.

C# has the exact same problem, which is solved in that environment by the StringBuilder class. In JavaScript, you'll get much better performance by building up an array of all the strings you want to concatenate, and then joining them together one time at the end, instead of a million times in the loop:

var parts = [];
for (var i = 0; i < 1000000; i++) {
    parts.push("hello");
}
var combined = parts.join(" ");
🌐
2ality
2ality.com › 2011 › 10 › string-concatenation.html
String concatenation in JavaScript
Collect the strings to be concatenated in an array and join it afterwards. > var arr = []; > arr.push("Say hello "); 1 > arr.push(7); 2 > arr.push(" times fast"); 3 > arr.join("") ’Say hello 7 times fast’ · Strings being immutable, most string operations whose results are strings produce new strings. Therefore languages such as C# or Java whose string handling is similar to JavaScript’s have special classes that help with concatenating strings.
🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions › javascript faq
Is it best practice to use string concatenation or string interpolation? Why? - JavaScript FAQ - Codecademy Forums
August 7, 2018 - Question Is it best practice to use string concatenation or string interpolation? Why? Answer String interpolation was a new feature of ES6 - string interpolation, using template literals, allows us to include variables and expressions in our ...
Find elsewhere
🌐
freeCodeCamp
forum.freecodecamp.org › t › which-is-more-efficient-str-some-string-or-array-push-join › 5802
Which is more efficient str += "some string" or array.push().join()
May 29, 2016 - I know String in JavaScript is immutable which means if I concatenate strings by using +=, a new string will be created with its content being copied from the old string, the old string then gets garbage collected, but …
🌐
W3Schools
w3schools.com › jsref › jsref_concat_string.asp
JavaScript String concat() Method
The concat() method returns a new string. ... let text1 = "Hello"; let text2 = "world!"; let text3 = "Have a nice day!"; let result = text1.concat(" ", text2, " ", text3); Try it Yourself » ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
SitePoint
sitepoint.com › blog › javascript › high-performance string concatenation in javascript
High-performance String Concatenation in JavaScript — SitePoint
November 5, 2024 - Both “+” and “concat()” can be used for string concatenation in JavaScript, but there are some differences. The “+” operator is more straightforward and easier to read, but it can lead to confusion if you’re trying to add a number to a string, as JavaScript will try to convert the string to a number.
🌐
Hashnode
darshitanjaria.hashnode.dev › mastering-javascript-the-battle-between-concat-and-template-literals
JavaScript Concat vs. Template Literals: Which One to Use?
April 18, 2025 - The JavaScript engine has to do more work to parse and process template literals, especially if they include embedded expressions or multi-line strings. While this overhead is generally negligible in modern applications, in performance-critical situations or on resource-constrained environments, the direct approach of concat() could be more efficient. ... Here, concat() directly performs the string concatenation without any additional parsing, which might be more optimal in specific cases.
🌐
Educative
educative.io › answers › string-concatenation-using-p-operator-vs-template-literals-in-js
String concatenation using + operator vs. template literals in JS
Repeated concatenation using the + operator, with variables and more strings, can lead to a lot of very hard-to-read code.
🌐
Reddit
reddit.com › r/javascript › why do javascript coders concatenate text using an array and .join()?
r/javascript on Reddit: Why do JavaScript coders concatenate text using an array and .join()?
September 30, 2012 -

I've been working on a project at work and one of the guys that was there before me and supposedly a senior web developer created a whole application with dynamically generated HTML code which looks something like this:

var name = 'Bob';
var text = [];

text.push('Hello ');
text.push(name);
text.push(" how's your day going?");
text.push('My day is going fine thanks ');
text.push(name);

text = text.join('');

Which completely baffled me. I would've thought it was cleaner and more readable to simply do:

var text = '';
var name = 'Bob';

text += 'Hello ' + name + " how's your day going?";
text += 'My day is going fine thanks ' + name;

Is there any reason for using the join() or concatenating the strings like that? I created a jsFiddle and it appears using the array and join() method is 3 times slower.

🌐
Reddit
reddit.com › r/learnjavascript › concat vs ${}
r/learnjavascript on Reddit: concat vs ${}
May 23, 2018 -

I'm learning Javascript through Udemy at the moment and they have just explained that you can inject variables into string using ${example} instead of concatenating.

What is the benefit to injecting variables this way instead of concatenating?

🌐
Reddit
reddit.com › r/webdev › template literals vs string concat.
r/webdev on Reddit: Template Literals vs String Concat.
June 1, 2020 -

Hi, I'm new-ish to web dev, by way of web design, by way of graphic design, so I have a lot to learn. I think maybe I'm missing something re template literals. consider:

return '<h1>Hello ' + firstName + ', welcome to your account.</h1>';

and

return `<h1>Hello '${ firstName }', welcome to your account.</h1>`;

Ok, so you're typing 1 less char, is that the only benefit? Are there performance benefits? It's certainly not significantly more legible or anything. What's the use case where template literals are just far and away superior to plain old string concat?


EDIT: Thanks everyone, I feel like I know when and how to use template literals now.

Top answer
1 of 5
27
Great question! For simple things like your example above, concatenation vs template literals provide very little benefit. Some would argue it's more readable, but that's about it. Template literals get more interesting when you're concatenating multiple variables though, or if you have escaped strings, for example: 'Hello ' + firstName + ', you\'re awesome'; vs Hello ${firstName}, you're awesome`; Minor benefit, but it can be useful. They shine even further though when you have to use multi-line strings (like HTML). A common way to do this before template literals was something like the following (or just appending \n to strings: [ 'Hello', firstName, 'welcome', 'to', 'your', 'account' ].join('\n') vs ` Hello ${firstName,} welcome to your account ` You can also evaluate expressions in template literals, for example `1 + 2 is ${1 + 2}` or `Hello ${firstName || 'unknown'}` etc. And lots lots more . Fundamentally though, it's going to just come down to your preferred coding style, though I imagine as you start concatenating lots of variables you'll quick find template literals great to use. As for performance, don't worry about it. Template Literals and String Concatenation constantly trade blows in browsers with what is faster one week vs the next week, but realistically they're both so fast and the variation between them is so minimal that it's almost certainly never going to be a bottleneck in your application.
2 of 5
7
In your template-literal example you don't need the single-quotes around the variable: so it's

Hello ${firstName}, welcome to your account.

; -- so it is a little easier to write and read. Opening and closing your strings a bunch of times can get tiresome. Also you can have any number of line breaks inside a template literal, which is a heck of a lot easier than having to close your string and add a + on every new line if you're using string concatenation on a big block of HTML. But point taken, string concatenation still works just fine if you prefer it. And it works on all browsers, which isn't true for template literals, so that's good too.
🌐
JavaScript Tutorial
javascripttutorial.net › home › top 3 practical ways to perform javascript string concatenation
Top 3 Practical Ways to Perform Javascript String Concatenation
September 9, 2020 - According to a performance test on some modern web browsers, the + and += operators perform faster than the concat() method. ES6 introduces the template literals that allow you to perform string interpolation.
🌐
CoreUI
coreui.io › blog › how-to-concatenate-a-strings-in-javascript
How to concatenate a strings in JavaScript? · CoreUI
April 4, 2024 - A: While there might be minor performance differences, they are negligible for most use cases. Focus on readability and the specific requirements of your javascript code. Whether you’re crafting a simple greeting message or generating complex dynamic content, mastering string concatenation techniques in JavaScript is essential.