Darrell Brogdon
Darrell Brogdon

Reputation: 6973

Which technique is more efficient?

In JavaScript is the former or the latter more efficient? Or is there even a difference?

// Method one
var path = first_part + '/' + second_part + '/' + third_part;

// Method two
var path = [first_part, second_part, third_part].join('/');

Beyond the savings of a whopping two characters there's no visual reason to prefer one over the other. But I'm curious to know if in most JavaScript interpreters one is faster or more efficient than the other and if so, is it significantly so?

Upvotes: 0

Views: 120

Answers (2)

Nick
Nick

Reputation: 6588

The second method is more efficient in terms of maintenance if you ever need to change the delimiter.

Upvotes: 2

Related Questions