summaryrefslogtreecommitdiffstats
path: root/closure.js
blob: 9c8743cb7735e60dac2bd636f170a34be720019f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function foo(n) {
    var f = 3.14;
    // closure, this anon func has access to 'n' and 'f'
    // outside of scope of 'foo'
    return function() {
        console.log(2 * n * f);
    }
}

var bar = foo(3);
bar();

// notes
// as soon as n and f were referenced on line 6, they now belong to
// a closure