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(";");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.