What happens with values in closure? JavaScript
问题 I've seen a really cool explanation of closure. So in my view closure is a way to store data somewhere. Let's see examples of closure and example without closure: Without closure: function F1(x,y) { var z=5; function F2(){ console.log('x='+x+'y='+y+'z='+z); } F2(); } F1(1,2) With closure: function F1(x,y) { var z=5; function F2(){ console.log('x='+x+'y='+y+'z='+z); } return F2(); } var p=F1(1,2) p(); I've understood that in closure when F1() finishes its work, then F1() clears connection to