scrimba
Advanced JavaScript I
JS 85 - Exercise: Counter object
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

JS 85 - Exercise: Counter object
AboutCommentsNotes
JS 85 - Exercise: Counter object
Expand for more info
index.js
run
preview
console
// 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]()
Console
0.5001069969494585
,
0.34829267134450625
,
0.7338964207128258
,
index.html
-0:56