Take for example this code:
var test = (function(){ var name = 'rar'; return function foo(){ console.log('test'); }; }());
foo returns to test with no references to name in the inner scope. What happens to name ? Ruined? Or does it continue to exist and hang out with the returned function, but simply cannot be accessed? The first case would be similar to doing the following, as if name had never been part of the equation ?:
var test = function foo(){ console.log('test'); };
Here is another case:
var test2 = (function(){ var name = 'rar'; var age = '20'; return function foo(){ console.log(age); }; }());
age gets the link foo and forms a closure. However, name still does not refer to anything. What happens to name in this case? Ruined? Or does it continue to exist and hang out with the return function, but simply cannot be accessed?
source share