Eishta Mittal
Nov 4, 2022

--

Hi André Moleirinho, Thanks for the question.

The value of 'this' in any function is either the object with which the function is called or it is the window object.

Here, we have stored the refernce of the function in stoleSecretIdenetity and we arre then calling stoleSecretIdenetity with no object (hence the value of this is window).

As there is no _name property on the window object, hence the value printed is undefined.

Whereas, in the second console statement, the context(value of this) is set to hero, so hero._name is printed.

--

--

Eishta Mittal
Eishta Mittal

Written by Eishta Mittal

Software Engineer passionate about Frontend Engineering

No responses yet