Strings in JavaScript are immutable. Across the web and here on Stack Overflow as well, I came across the Array approach to concatenate strings:
var a = [];
a.push(arg1,arg,2....);
console.log(a.join(''));
I know that this approach is better than the simple
console.log(arg1 + arg2 +.....);
for reasons of skipping creating intermediate objects but how does it fair better against :
arg1.concat(arg2,arg3.....);
For what it may count, I tried the following test:
Results in Firefox 3.6.3 on Mac OS X 10.6.2:
Results in Chrome 5.0 on Mac OS X 10.6.2:
UPDATE:
If we were to count the array creation in the
join('')test, we would see a different story. Testing:Results in Firefox 3.6.3 on Mac OS X 10.6.2:
Results in Chrome 5.0 on Mac OS X 10.6.2: