this keyword in javascript

kali
Tera Contributor

Hi All,

Please explain to me how this keyword in javascript is working. I went through the documentation still it is confusing . Thanks in advance

1 REPLY 1

Robbie
Kilo Patron
Kilo Patron

Hi @kali,

 

It's use depends on the context. A good reference site and starting point for all things JavaScript is www.w3schools.com.

 

In JavaScript, the this keyword refers to an object.

The this keyword refers to different objects depending on how it is used:

In an object method, this refers to the object.
Alone, this refers to the global object.
In a function, this refers to the global object.
In a function, in strict mode, this is undefined.
In an event, this refers to the element that received the event.
Methods like call(), apply(), and bind() can refer this to any object.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.


Thanks, Robbie