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


James Koppenal
James Koppenal
Courses Plus Student 9,285 Points

Why use a $ in the variable as oppose to using without it? Any difference? And what is the best practice?

var $select = $("<select></select>");



var select = $("<select></select>");


2 Answers

A $, is an alias for jQuery. Some people prefer to put a dollar sign together with the variable to make a distinction between regular vars and jQuery objects.

Zachary Billingsley
Zachary Billingsley
6,187 Points


Typically you don't see symbols at the beginning of javascript variables. While it does still work, I would advise against it. If you are mixing javascript and php code, the variables may look similar and get confusing (since php variables are denoted by a "$"). $ is also used in most jQuery code, like you have above, so it is an easy indication of when you are using jQuery instead of plain javascript.

Hope that helps!