We knew that
function foo () {
var x = 10;
var y = 20;
function bar () {
return x + 1;
}
bar(); // 11
}
The function bar
create a closure, and save the reference of x
.
But what about the variable y
? Will the closure bar
created hold its reference? I tried it in Chrome Dev Tools, and it shows only x
in the [[Scopes]]
field, without y
. But I can not find any articles about that.
Does it means the closure creation will only pick what it need to save?