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
🌐
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 ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › concat
String.prototype.concat() - JavaScript | MDN
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.
🌐
ReqBin
reqbin.com › code › javascript › 9wnknlf8 › javascript-string-concatenation-example
How do I concatenate strings in JavaScript?
The string.concat() method does not modify the provided strings but creates and returns a new string resulting from the concatenation. In this JavaScript String Concatenate example, we use the string.concat() method to concatenate strings.
Top answer
1 of 6
137

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';
}

🌐
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.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › string-concat
3 Ways to Concatenate Strings in JavaScript - Mastering JS
You can concatenate strings in JavaScript using the `+` operator, the `Array#join()` function, or the `String#concat()` function. Here's what you need to know.
🌐
SamanthaMing
samanthaming.com › tidbits › 15-4-ways-to-combine-strings
4 Ways to Combine Strings in JavaScript | SamanthaMing.com
4 ways to combine strings in JavaScript. My favourite way is using ES6’s Template Strings...
🌐
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.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-concatenate-strings-in-javascript
Concatenation of Strings in JavaScript - GeeksforGeeks
September 13, 2023 - Easy to use for basic string concatenation. Works with all types of strings and variables. The concat() method is a built-in JavaScript function that combines multiple strings into one.
🌐
OneCompiler
onecompiler.com › javascript › 3x3rxvsze
String concatenation - JavaScript - OneCompiler
Executable in both browser and server which has Javascript engines like V8(chrome), SpiderMonkey(Firefox) etc.
🌐
SitePoint
sitepoint.com › blog › javascript › high-performance string concatenation in javascript
High-performance String Concatenation in JavaScript — SitePoint
November 5, 2024 - String concatenation is crucial in web applications, and JavaScript offers several ways to accomplish this, including the use of the “+” operator, the “+=” operator, the “concat” method, and joining an array of strings.
🌐
Turing
turing.com › kb › guide-to-string-concatenation-in-js
Your Guide to String Concatenation in JavaScript
For example, if you want to concatenate ... discuss the various ways to combine strings in JS. In JavaScript, the “+” operator can be used to add strings together....
🌐
freeCodeCamp
freecodecamp.org › news › how-js-string-concatenation-works
JavaScript Concatenate Strings – How JS String Concatenation Works
May 7, 2024 - You can also use the built-in concat() method to concatenate two or more strings in JavaScript.
🌐
Scaler
scaler.com › home › topics › 4 ways to concatenate strings in javascript
4 Ways to Concatenate Strings in JavaScript - Scaler Topics
January 6, 2024 - The JavaScript String Concatenation method joins two or more strings without changing the existing strings, hence returning a new string. Learn the methods of String Concatenation here.
🌐
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.
🌐
TechOnTheNet
techonthenet.com › js › string_concat.php
JavaScript: String concat() method
You can use the concat() method with an empty string variable to concatenate primitive string values.
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › String › concat
JavaScript String concat() - Concatenate Strings | Vultr Docs
November 14, 2024 - ... let str = "Result: "; let result ... " with undefined results in "Result: undefined". The concat() function in JavaScript offers a seamless and effective way to join strings, whether you're dealing with text, numbers, or other ...
🌐
Useaxentix
useaxentix.com › blog › javascript › concatenate-strings-in-javascript
Concatenate Strings in JavaScript: Complete Guide
Master JavaScript string concatenation with + operator, template literals, concat(), and join(). Learn performance tips, best practices, and real-world examples for string append operations.
🌐
Intellipaat
intellipaat.com › home › blog › javascript string concatenation
JavaScript String Concatenation: 5 Easy to Combine Strings
December 17, 2025 - Learn how to concatenate strings in JavaScript using +, concat(), join(), and template literals with syntax, examples, best practices, and tips.