this keyword
In the global execution context, this keyword refers to the global object which is window.
Generally , this keyword will refer to the object it belongs to.
Example :
In a method, this refers to the owner object.
Example :
In above example, at the time of invocation, the getName function is a property of the object person, therefore the this keyword will refer to the object object person , hence the output is ‘Ameer’.
Example :
In above example, although the getName function is declared inside the object person , at the time of invocation, getName() is a property of newPerson , therefore the “this” keyword will refer to object newPerson .