Learn JavaScript
this on Objects

this in methods

Sometimes the method needs to access the object. In such cases, the method can use the this keyword.

The value of this is the object that precedes the dot operator during execution.

In the example given above, the admin object precedes the dot operator during the execution of admin.sayHello(). Therefore, the value of this will be admin.

We can also access the object using the admin.name instead of using this. But this approach is unreliable as it may access the wrong object in large programs.