// https://javascript.info/closure // Garbage collection function f() { let value = Math.random();
return function() { console.log(value); }; }
// 3 functions in array, every one of them links to Lexical Environment // from the corresponding f() run // LE LE LE let arr = [f(), f(), f()]; arr[0]() arr[1]() arr[2]()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// https://javascript.info/closure
// Garbage collection
function f() {
let value = Math.random();
returnfunction() { console.log(value); };
}
// 3 functions in array, every one of them links to Lexical Environment