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

Ben Os
Ben Os
20,008 Points

this in Javascript --- Usable in all cases when the dot accessor (.) isn't ?

Is it true to sum up and say that the *** this *** accessor is usuable in all cases when the dot accessor (.) isn't useful?

This is the only reason I could give to even inventing *** this *** in the first place: Accessing all these values, methods, ivoked functions or constructor outputs.

I will thank you for your reply.

Huston Hedinger , Joel Kraft

Joel Kraft
Joel Kraft
Treehouse Guest Teacher

Hi Ben,

I'm not sure if I understand what you're asking. Are you talking about the this keyword vs. a dot accessor? (Those are two very different things.)

Perhaps if you post some code I might be able to follow better.

Joel

Ben Os
Ben Os
20,008 Points

Exactly Joel. I think I miss the difference between the two --- this VS the dot accessor. Joel Kraft

1 Answer

Joel Kraft
STAFF
Joel Kraft
Treehouse Guest Teacher

Ben,

The JavaScript keyword this is not an accessor. It is a keyword that behaves like a variable name (or more formally an identifier), and it always points to an object.

The dot is an accessor. You can use the dot to access properties on any object (which means you can use it to access properties on this).

In other words, the two are not mutually exclusive, and in fact this is rarely used without an accessor. That's because when this is used, it's usually only needed for one of the properties it contains.

Does that help differentiate the two?

By the way, I'm not sure if you've checked out our workshop on this yet, but here's a link to that in case it helps.

Ben Os
Ben Os
20,008 Points

Yes Joel. It fully cleared the difference for me. I thank you deeply for this super-didactic elaboration!