From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext

Unlock this course with a free trial

Join today to access over 25,000 courses taught by industry experts.

Learn about the this keyword in JavaScript

Learn about the this keyword in JavaScript

- So far in the course, there have been quite a few references to the this keyword in JavaScript, but so far, we haven't really talked about it in any detail. Let's do that now. The this keyword can be a pretty big source of confusion and frustration for programmers coming to JavaScript from another language like Java, where this behaves a little more predictably. In most other programming languages, this, or whatever the related keyword is in that language, is simply a keyword that you can use inside the class definition to refer to a specific instance of that class. For example, if we have a class with a name member variable and we say this.name, we're referring to whatever the value of the name property happens to be on a specific instance. And in JavaScript, the this keyword is used in this way, as well. The place where the confusion comes in, however, is that we're allowed to use this in other situations than you might be used to. And in this video, we're going to take a look at…

Contents