According to the documentation, the difference between using + and concat() is that contat() will convert the argument directly to a string while the + operator will convert the operands to a primitive value and then into a string. Summarizing, it will not make a significant difference.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat#description
The time complexity of concat operations in another language like Java is usually O(n^2), and is a common practice to use a StringBuilder to make it O(n). In JavaScript though, there is an optimized implementation of concatenation based on the rope data structure, making the time complexity O(log n) in most cases.
https://josephmate.github.io/java/javascript/stringbuilder/2020/07/27/javascript-does-not-need-stringbuilder.html
Answer from Artur Luis on Stack OverflowJavascript - Time and space complexity of splice and concat inside loop - Stack Overflow
Time and space complexity of string iteration and concatenation in javascript - Stack Overflow
JavaScript Array.push is 945x faster than Array.concat
javascript - Why is + so bad for concatenation?
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.
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(" ");