For this code I want to know in javascript what is the best approach?
var output = foo +";"+bar;
or
var output = new Array(foo,bar).join(";");
It doesn't really matter.
There were blogs promoting the first one or the second one, depending on their benchmarks.
But the truth is that javascript engines are heavily optimized and changing, so you won't find a big reproducible and cross-browser difference.
Choose the most readable. Generally it's the first one.
If you really do a loop with 10000 times this push, benchmark it on your customer browsers in your real code, and choose the best but only if there is a significative difference. Don't forget that javascript is fast.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With