I am using D3.js and often find myself dynamically building transform
attributes (or d
attributes on path
elements). Both of these of
When JavaScript coerces an array to a string, it actually call: .join(',')
on the array. So you're actually going to be getting better performance with .join(',')
manually as opposed to leaving it up to the interpreter to notice you're coercing the array. So: x + ',' + y
is the fastest, [x, y].join(',')
is the best practice(since it makes it easier to modify the behavior), and [x, y]
is a tiny bit slower than manually calling .join
and can be unreadable at times, but it's more convenient.