Video Lesson

Lesson Notes

Using this in Object Methods (Simple)

The this keyword inside an object method refers to the object itself, letting you access its properties.

Example Object

1const person = { 2 name: "Alice", 3 age: 30, 4 printAge: function() { 5 console.log(this.age); 6 } 7};
  • this.age accesses the age property on person.

Calling the Method

1person.printAge(); 2// Logs: 30
  • When you call person.printAge(), this inside printAge points to person.
  • You can reference any property: this.name, this.someOtherProp, etc.

Why Use this?

  • Allows methods to work with their own object’s data.
  • Makes methods reusable across different objects if needed.

AI Assistant

Sign In Required

Sign in and subscribe to use the AI assistant for instant help with your lessons.

Sign In

Basic This

The `this` keyword in object methods. In this lesson, you'll learn how to access and manipulate object properties, enhancing your JavaScript skills and enabling methods to dynamically interact with their own data, making your code more efficient and reusable.

1m 17s

Course Content

0 of 32 lessons completed
6. Promises, Async and Await
0 of 0 completed
7. The DOM
0 of 0 completed