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 Introduction to jQuery DOM Manipulation Adding Content to the Page

If $name is a convention used for variables that hold jQuery objects, why are they being assigned the return of val()?

As far as I can tell, a jQuery object's val() method does not return a jQuery object, it returns a string or other primitive like a number/array.

3 Answers

Steven Parker
Steven Parker
231,269 Points

:point_right: Prefixing a value variable name with a dollar sign ($) is not conventional.

I agree with Simon, this is not the convention for jQuery variable naming.

You might want to report it as a bug on the Support page.

Simon didn't say that $name wasn't the conventional naming scheme for jQuery objects, and neither did I. If you watch the video, you'll see that she explains the naming convention and then proceeds to use it to prefix variables that are NOT jQuery objects. That is inconsistent and confusing, and obviously a mistake.

Hi Arya,

I think you might have misunderstood Steven's answer. Steven is in agreement with you and Simon as far as I can tell.

I'll notify staff to see if a correction can be made.

Simon Coates
Simon Coates
28,694 Points

It may be in reference to future usage. I have some recollection that she removes the .val() bit at a later point when she wants to use the variable in a couple different ways. I could be wrong. But you're right, for now, she does seem to be using a jquery variable convention for variables that are strings.

If memory serves me correct, you don't need to use the "$" when naming jQuery variables, but by using it, you can better read /understand your code, so that you immediately know it's used to store a jQuery variable.