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

Variable naming in JQuery

I am working on the JQuery course of my track and have noticed the instructor periodically will declare a variable using a dollar sign ($) at the start of the name, and other times will declare a variable in a more regular fashion (as in, starting with a letter). I know that the "$" at the front of the variable name does not make a difference in its behavior or functionality but I was wondering why one might name some variables with the dollar sign at the start and others without; is there some kind of semantic meaning associated with one or the other? Thanks!

1 Answer

Steven Parker
Steven Parker
243,656 Points

When using JQuery, the $ itself becomes an abbreviation for "JQuery".

As a convention, programmers will often use a $ to start a variable name if that variable will be used to hold a JQuery object. This makes it easy to remember later that you can apply JQuery extension methods to them.

Happy coding!   -sp:sparkles: