0

I have been learning D3 for the past weeks and I have an understanding of the concepts and created some animations and maps with it, however I am having trouble understanding one syntax construct:

attr("transform", "translate(" + 100 + ",0)");

I know what it does and how to use it, however I wonder why I need to put "+" before and after the "100"? I haven't had much experience with javascript before...

1 Answer 1

3

You do not have to use '+' in your example. But you have to do it when 100 is value of the variable eg:

var a = 100;
attr("transform", "translate(" + a + ", 0)");

The '+' in this case is simple string concatenate operator and it just adding the text "100" inside the string. So it's result is: attr("transform", "translate(100 ,0)");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.