About this keyword | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

About this keyword

Can anyone help me with what exactly the use of this keyword

20th Aug 2021, 6:58 PM
prayag bhimani
prayag bhimani - avatar
1 Answer
+ 6
The JavaScript "this" keyword refers to the object it belongs to. It has different values depending on where it is used: 1) In a method, this refers to the owner object. 2) Alone, this refers to the global object. 3) In a function, this refers to the global object. 4) In a function, in strict mode, this is undefined. 5) In an event, this refers to the element that received the event. 6) Methods like call(), and apply() can refer this to any object. More info: https://www.w3schools.com/js/js_this.asp https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
20th Aug 2021, 7:03 PM
David García Prados