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!

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


this keyword in function

When the this keyword is in a normal function is it a reference to the global function or is it the global context?

1 Answer

Jake Salo
Jake Salo
13,175 Points

When the 'this' keyword is used in a Function Declaration, it will refer to the active window in the user's browser.

Try calling this function in the console, and see what it returns:

function testThis() {

It is however dependant on the scope of the function in question, so object methods will refer to the parent object.