Can someone explain this to me:
http://jsperf.com/string-concatenation-1/2
If you are lazy, I tested A) against B):
A)
var innerHTML = "";
items.forEach(function(item) {
innerHTML += item;
});
B)
var innerHTML = items.join("");
Where itemsfor both tests is the same 500-element array of strings, each row being random and 100 to 400 characters long.
A) ends 10 times faster. How it could be - I always thought concatenating with join("")was an optimization trick. Is there anything missing in my tests?
source
share