With ES6, you can use

  • Template strings:

    var username = 'craig';
    console.log(`hello ${username}`);
    

ES5 and below:

  • use the + operator

    var username = 'craig';
    var joined = 'hello ' + username;
    
  • String's concat(..)

    var username = 'craig';
    var joined = 'hello '.concat(username);
    

Alternatively, use Array methods:

  • join(..):

    var username = 'craig';
    var joined = ['hello', username].join(' ');
    
  • Or even fancier, reduce(..) combined with any of the above:

    var a = ['hello', 'world', 'and', 'the', 'milky', 'way'];
    var b = a.reduce(function(pre, next) {
      return pre + ' ' + next;
    });
    console.log(b); // hello world and the milky way
    
Answer from typically on Stack Overflow
Top answer
1 of 6
138

With ES6, you can use

  • Template strings:

    var username = 'craig';
    console.log(`hello ${username}`);
    

ES5 and below:

  • use the + operator

    var username = 'craig';
    var joined = 'hello ' + username;
    
  • String's concat(..)

    var username = 'craig';
    var joined = 'hello '.concat(username);
    

Alternatively, use Array methods:

  • join(..):

    var username = 'craig';
    var joined = ['hello', username].join(' ');
    
  • Or even fancier, reduce(..) combined with any of the above:

    var a = ['hello', 'world', 'and', 'the', 'milky', 'way'];
    var b = a.reduce(function(pre, next) {
      return pre + ' ' + next;
    });
    console.log(b); // hello world and the milky way
    
2 of 6
29

I'm disappointed that nobody in the other answers interpreted "best way" as "fastest way"...

I pulled the 2 examples from here and added str.join() and str.reduce() from nishanths's answer above. Here are my results on Firefox 77.0.1 on Linux.


Note: I discovered while testing these that if I place str = str.concat() and str += directly before or after each other, the second one always performs a fair bit better... So I ran these tests individually and commented the others out for the results...

Even still, they varied widely in speed if I reran them, so I measured 3 times for each.

1 character at a time:

  • str = str.concat(): 841, 439, 956 ms / 1e7 concat()'s
  • ............str +=: 949, 1130, 664 ms / 1e7 +='s
  • .........[].join(): 3350, 2911, 3522 ms / 1e7 characters in []
  • .......[].reduce(): 3954, 4228, 4547 ms / 1e7 characters in []

26 character string at a time:

  • str = str.concat(): 444, 744, 479 ms / 1e7 concat()'s
  • ............str +=: 1037, 473, 875 ms / 1e7 +='s
  • .........[].join(): 2693, 3394, 3457 ms / 1e7 strings in []
  • .......[].reduce(): 2782, 2770, 4520 ms / 1e7 strings in []

So, regardless of whether appending 1 character at a time or a string of 26 at a time:

  • Clear winner: basically a tie between str = str.concat() and str +=
  • Clear loser: [].reduce(), followed by [].join()

My code, easy to run in a browser console:

{
  console.clear();

  let concatMe = 'a';
  //let concatMe = 'abcdefghijklmnopqrstuvwxyz';

  //[].join()
  {
    s = performance.now();
    let str = '', sArr = [];
    for (let i = 1e7; i > 0; --i) {
      sArr[i] = concatMe;
    }
    str = sArr.join('');
    e = performance.now();
    console.log(e - s);
    console.log('[].join(): ' + str);
  }

  //str +=
  {
    s = performance.now();
    let str = '';
    for (let i = 1e7; i > 0; --i) {
      str += concatMe;
    }
    e = performance.now();
    console.log(e - s);
    console.log('str +=: ' + str);
  }

  //[].reduce()
  {
    s = performance.now();
    let str = '', sArr = [];
    for (let i = 1e7; i > 0; --i) {
      sArr[i] = concatMe;
    }
    str = sArr.reduce(function(pre, next) {
      return pre + next;
    });
    e = performance.now();
    console.log(e - s);
    console.log('[].reduce(): ' + str);
  }

  //str = str.concat()
  {
    s = performance.now();
    let str = '';
    for (let i = 1e7; i > 0; --i) {
      str = str.concat(concatMe);
    }
    e = performance.now();
    console.log(e - s);
    console.log('str = str.concat(): ' + str);
  }

  'Done';
}
Run code snippetEdit code snippet Hide Results Copy to answer Expand

🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › string-concat
3 Ways to Concatenate Strings in JavaScript - Mastering JS
July 29, 2019 - The same + operator you use for adding two numbers can be used to concatenate two strings. const str = 'Hello' + ' ' + 'World'; str; // 'Hello World' You can also use +=, where a += b is a shorthand for a = a + b. let str = 'Hello'; str += ' ...
Discussions

Most efficient way to concatenate strings in JavaScript? - Stack Overflow
In JavaScript, I have a loop that has many iterations, and in each iteration, I am creating a huge string with many += operators. Is there a more efficient way to create a string? I was thinking ab... More on stackoverflow.com
🌐 stackoverflow.com
What is the most efficient way to concatenate a string? (For example chat GPT stream responses)
Use an array of strings, push to append and then use join to get the final result. Effectively the same as a string builder More on reddit.com
🌐 r/node
8
5
October 7, 2023
Seven ways to concatenate strings in rust. The second one really blew me away.
Stitch strings together with this one weird trick, arrays hate him! More on reddit.com
🌐 r/rust
52
76
March 1, 2016
I was curious what way to concatenate strings in PHP is the fastest. Here are my results in PHP 5.6 and PHP 7.
If you really want to examine PHP performance at this level, you should be looking at opcodes. Davey Shafik did a talk that's a good introduction to this: PHP Under The Hood . While it's from before PHP 7, the basics still apply - PHP 7 did add another layer to compilation, the Abstract Syntax Tree, that you might want to also look at tho. You should also read up on PHP's opcache. As already mentioned tho, this type of micro-optimization is almost certainly not going to produce significant performance benefits. To produce the best performance gains, you need to benchmark your actual application code to work out where the slowdowns / bottlenecks are and fix those - you'll most likely gain much more by fixing your database schema and indexes and refactoring code to reduce the number of times you loop over data sets. And that's not even going into perceived speedups that can be gained from improved UI feedback - Got a page that takes a little too long to load? Put a loading animation on links to it and rake in the praise for speeding things up, even tho the page still takes exactly the same amount of time to load. More on reddit.com
🌐 r/PHP
54
52
October 24, 2016
🌐
SitePoint
sitepoint.com › blog › javascript › high-performance string concatenation in javascript
High-performance String Concatenation in JavaScript — SitePoint
November 5, 2024 - One method is to use the “+=” operator instead of the “+” operator, as it’s faster and more efficient. Another method is to use an array and the “join()” method, which can be faster for large amounts of data. However, the best method depends on your specific use case and the size ...
🌐
Mimo
mimo.org › glossary › javascript › string-concatenation
JavaScript String Concatenate: Syntax, Usage, and Examples
Combine text dynamically using JavaScript string concatenation. Use +, concat(), or template literals to format output, build messages, or personalize content.
🌐
Useaxentix
useaxentix.com › blog › javascript › concatenate-strings-in-javascript
Concatenate Strings in JavaScript: Complete Guide
October 13, 2025 - Master JavaScript string concatenation with the + operator, template literals, concat(), and join() methods. Learn performance tips, best practices, and real-world examples for efficient string operations.
🌐
Medium
medium.com › @uomroshan › methods-of-string-concatenation-in-javascript-fe1374008069
Methods of String Concatenation in JavaScript | by Roshan Maddumage | Medium
June 24, 2024 - The concat() method can be used to concatenate multiple strings. This method does not change the existing strings but returns a new string containing the combined text of the strings. let str1 = "Hello"; let str2 = "World"; let result = ...
Find elsewhere
🌐
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 ...
🌐
Turing
turing.com › kb › guide-to-string-concatenation-in-js
Your Guide to String Concatenation in JavaScript
The variable substitution method of template literals is one of the best ways to concatenate strings in JavaScript.
🌐
CoreUI
coreui.io › blog › how-to-concatenate-a-strings-in-javascript
How to concatenate a strings in JavaScript? · CoreUI
April 4, 2024 - It’s a fundamental concept that finds application in creating dynamic content, processing user inputs, and much more within web development. The simplest way to concatenate strings is by using the + operator.
🌐
MSR
rajamsr.com › home › javascript string concatenation: 6 easy ways to do it
JavaScript String Concatenation: 6 Easy Ways To Do It | MSR - Web Dev Simplified
March 16, 2024 - The concatenation operator (+) is the most common and straightforward way, while the template literals and join() method provide additional functionality and readability. Now that you know how to concatenate strings in JavaScript, you can choose ...
🌐
Scaler
scaler.com › home › topics › 4 ways to concatenate strings in javascript
4 Ways to Concatenate Strings in JavaScript - Scaler Topics
January 6, 2024 - Here, with the help of $ and curly braces, we can embed a variable in our string quoted under back-ticks, indicating string concatenation :) ... In this JavaScript example, we have initialized three string variables at the start, and then with the concept of template literals, we have embedded str1, str2, and str3 in the string - final_str quoted under back-ticks. In this way, we can write exactly how we want our string to appear as output and also, it becomes easy to spot the missing spaces between the words.
🌐
Medium
medium.com › @ryan_forrester_ › string-concatenation-in-javascript-a-comprehensive-guide-fa3f46e6a227
String Concatenation in JavaScript: A Comprehensive Guide | by ryan | Medium
March 2, 2025 - By being familiar with the different methods available-such as the plus operator, plus equals, template literals, and the concat() method-you can choose the most appropriate approach for your specific use case.
🌐
DEV Community
dev.to › tpointtech123 › a-step-by-step-guide-to-string-concatenation-in-javascript-1h3a
A Step-by-Step Guide to String Concatenation in JavaScript - DEV Community
March 20, 2025 - This operation is used frequently when working with variables, strings, and expressions in web development. Method 1: Using the + Operator The simplest and most common way to concatenate strings in JavaScript is by using the + operator.
🌐
SamanthaMing
samanthaming.com › tidbits › 15-4-ways-to-combine-strings
4 Ways to Combine Strings in JavaScript | SamanthaMing.com
Here are 4 ways to combine strings in JavaScript. My favorite way is using Template Strings.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-concatenate-strings-in-javascript
Concatenation of Strings in JavaScript - GeeksforGeeks
January 17, 2026 - The + (plus) operator is the most common way to concatenate strings. It’s simple to use, and you can combine two or more strings with a plus sign between them. ... let fName = "Mohit"; let lName = "Kumar"; let fullName = fName + " " + lName; ...
🌐
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 - The following example shows how ... In this tutorial, you have learned how to concatenate strings in JavaScript using the concat() method, + and += operator, and template literals....
🌐
Technource
technource.com › blog › string-concatenation-in-javascript
String Concatenation in JavaScript:Techniques and Best Practices
April 8, 2024 - A method like `concat()` is used to combine strings in JavaScript. Other ways of concatenation are the `+` operator, template literals, and array join().
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › concat
String.prototype.concat() - JavaScript - MDN Web Docs
It should only happen if you are spreading an array of strings as arguments, and that array happens to be empty. A new string containing the combined text of the strings provided. The concat() function concatenates the string arguments to the calling string and returns a new string.
🌐
Intellipaat
intellipaat.com › home › blog › javascript string concatenation
JavaScript String Concatenation: 5 Easy to Combine Strings
December 17, 2025 - Whether you use the + operator, concat() method, template literals, or the array.join(), each of these approaches allows you to combine text in different ways based on your needs.