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 Hello, jQuery! Filtering Matched Elements

Omar Hamza
PLUS
Omar Hamza
Courses Plus Student 1,985 Points

What is the function's "this" keyword?

I just want to understand function's "this" keyword because it has not been taught in the previous courses. Thank you.

David Moody
David Moody
19,302 Points

Here is the video from Treehouse about the "this" keyword. You see it in JavaScript and Java:

https://teamtreehouse.com/library/understanding-this-in-javascript

1 Answer

Steven Sullivan
Steven Sullivan
11,616 Points

'this' typically refers to a particular use of a previously declared variable.

What it's doing, is telling you that the instance of this variable is specific to this function, but may have a different value in another function. It's THIS functions instance of the variable I made earlier.

For example, if you had:

var word;

function test() {
this.word = testword;
}

What this does it change THAT FUNCTIONS var word, instead of changing the global var word.