Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialYuttanant Suwansiri
1,608 Pointswhy was mySVG variable not declared with var in front of it?
have this question on d3.js tutorial from this link https://teamtreehouse.com/library/d3js/selections-with-d3js/svg-graphics
1 Answer
Ionut Costica
737 PointsI don't think there was any particular reason to it as he's not re-using the variable outside the function it's declared in. He probably just forgot the "var". (It works, because if you don't put in the "var" in cases like these, it declares a global variable instead of a local one. For more information see here under heading 'Automatically Global')
Yuttanant Suwansiri
1,608 PointsYuttanant Suwansiri
1,608 PointsThank you so much for your answer, that makes sense now so it would automatically becomes a global variable, I learn something new, thank you :-)