
Understanding this, call(), apply(), and bind() in JavaScript
In JavaScript, the keyword this is used inside functions to refer to the object that is calling the function. A simple way to think about it is: this means “who is calling the function.” Understanding this helps when working with objects, methods, and advanced function behaviors. What this Means in JavaScript The value of this depends on how a function is called . Example: let person = { name : " Alice " , greet : function () { console . log ( " Hello, my name is " + this . name ); } }; person . greet (); Output: Hello, my name is Alice Here: this refers to the person object this.name accesses the object's property this Inside Normal Functions In a normal standalone function, this usually refers to the global object (or undefined in strict mode). Example: function showThis () { console . log ( this ); } showThis (); Since the function is not called by any object, this does not refer to a specific object. this Inside Objects When a function is called as a method of an object , this refe
Continue reading on Dev.to Webdev
Opens in a new tab



