can u explain me how this keyword works in js with some example and with its functionality
This keyword doubt
In simple language, this refers to object a variable/function/data belongs to. For eg:
const person = {
firstName: “John”,
lastName: “Doe”,
id: 5566,
fullName : function() {
return this.firstName + " " + this.lastName;
}
};
console.log(person.fullName);
Try using the above example without this, you will see it does not console anything because firstname and lastname do not exist in function but after using this it refers to object and prints output.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.