Learn JavaScript
this on Objects

this is not bound

In JavaScript, the value of this does not depend on where the method is declared. Instead, it depends on the object that precedes the dot operator during execution. It means that this is not bound.

In the example given below, we assign this two different objects.

Here, when admin.greetings() executes, the value of this is admin and when user.greetings() executes, the value of this is user.