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 trial

JavaScript jQuery Basics (2014) Creating a Simple Drawing Application Perform: Part 1

Why use "color" instead of "$color" in naming the variable?

I thought it was ideal to append the $ sign when we are using jQuery? Or do we remove $ for global variables?

1 Answer

You would use the $ when you're saving the variable as a jQuery object, but not when the variable is only information drawn from that object. So in this instance, if you planned on using $(".selected") repeatedly, you could cache that as a variable named $selected. However, since it's var color = $(".selected").css("background-color"), the var color only stores the CSS property, which isn't a jQuery object.

Just remember, adding $ to variables is only for caching jQuery objects that will be repeatedly searched.

Thanks Adam!

Good question and good answer!!