When I execute this code
f= function(){
let test= "hello";
let ret={
"test": "world",
"func": function(){
console.log(test);
}
}
return ret;
}
let check= f();
check.func()
I get output as "hello". But I am not able to figure out why it is happening. According to what I have read, the scope chain get stacked over each other during definition and last block of scope is attached on runtime on top of them. So shouldn't the scope chain be like- global -> function f -> ret Object -> function test ? Why are the members of ret object excluded from scope chain ? Is it something like members of object are not attached to scope and are just part of context ?