This Keyword
In JavaScript, the this keyword is a little different compared to other languages. It refers to an object, but it depends on how or where it is being invoked. It also has some differences between strict mode and non-strict mode.
- In an object method,
thisrefers to the object - Alone,
thisrefers to the global object - In a function,
thisrefers to the global object - In a function, in strict mode,
thisis undefined - In an event,
thisrefers to the element that received the event - Methods like call(), apply(), and bind() can refer
thisto any object
Visit the following resources to learn more: