Reputation: 3020
What is the Difference between declaring an array with elements and declaring it and iterating the elements into it in Javascript?
r = [req.body.email,
req.body.password];
vs
r=[];
r.push(req.body.email, req.body.password);
Upvotes: 0
Views: 83
Reputation: 58601
Biggest difference is code readability. They are functionally equivalent.
Depending on the javascript engine, one might perform faster than the other, but the difference is negligible.
You can measure the exact performance on jsperf, something like this: http://jsperf.com/assignment-vs-push/7
Run the test in different browsers to see different results, but looks to me like the direct assignment is faster.
Upvotes: 4