Skip to content

Latest commit

 

History

History
13 lines (7 loc) · 554 Bytes

what-below-code-will-output-2.md

File metadata and controls

13 lines (7 loc) · 554 Bytes

Q - What will be the output of the below code and why

Ans - The above code will output the following to the console:

Explanation

In the outer function, both this and self refer to myObject and therefore both can properly reference and access foo.

In the inner function, though, this no longer refers to myObject. As a result, this.foo is undefined in the inner function, whereas the reference to the local variable self remains in scope and is accessible there.