Is [x,y,z].join('') really faster than x + y + z for strings?
Under the impression that join() is faster, I started through my code to use it rather than +, then I ran into the following line in the Google Analytics code:
ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
Assuming the Google coders are among the most knowledgeable, it makes me wonder. Of course, that line is only going to run once per page load, and one could say that any speed difference is negligible. But still?
Using Firebug Console in Firefox 6.0.2 using the following code:
and
I average in the low 40s for “+” and low 50s for “join” so it seems join is slower. This is most likely because of the need to create an array for join. Also this may be different in different browsers with different interpreters.