In JavaScript, the this keyword refers to an object.
The object that this refers to varies depending on how it is used.
|
In an object method, this refers to the object that the method is a part of. |
|
When used alone, this refers to the global object. |
|
In a function, this refers to the global object. |
|
In strict mode, this is undefined inside a function. |
|
In an event handler, this refers to the element that triggered the event. |
|
Methods like call(), apply(), and bind() can explicitly set the value of this to any object. |
|
Note: this is not a variable; it is a keyword. You cannot change its value. |