Check out a free preview of the full Deep JavaScript Foundations course:
The "this" Lesson is part of the full, Deep JavaScript Foundations course featured in this preview video. Here's what you'd learn in this lesson:

Kyle reviews the "this" function. Every function, while it's executing, has a reference to its current execution context called "this." The "this" reference is JavaScript's version of dynamic scope. Kyle explains the "this" keyword's relationship to the call site of the function.

Get Unlimited Access Now

Transcript from the "this" Lesson

[00:00:00]
>> Kyle: Let's look at the this keyword. And in particular, I wanna help you understand how that fits compared to what we've learned with lexical scope. So every function while it's executing has a reference to its own current execution context. And we call that reference the this keyword. There's an asterisk next to every, which we're gonna come back to later.

[00:00:20] There are some functions now which don't have a this keyword, namely arrow functions. But we'll come back to that topic a little bit later. Do you remember that whole discussion of lexical versus dynamic scope? And I hinted that JavaScript had this thing that was kind of like dynamic scope.

[00:00:36] That thing is the this keyword. So if lexical scope is this fixed predictable thing, the this keyword is this dynamic flexible thing. And what's beautiful about JavaScript is that we have both mechanisms, they are parallel mechanisms in the language. Visually, we can see that there's actually a true parallel symmetry here.

[00:00:58] If the current scope represents where we start looking for something, and then we go up the lexical scope chain to look for something, the this keyword represents where we're gonna start in a dynamic context. And then we're gonna look at what the elevator of that building looks like after we've looked at the this keyword.