public
Created

Closure in action

  • Download Gist
closure.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
(function () {
"use strict";
 
function level1() {
var a = 'hello';
 
function level2() {
console.log(a);
 
setTimeout(function () {
console.log(a);
}, 100);
 
a = 'goodbye';
}
 
a = 'peekabo';
 
setTimeout(function () {
console.log(a);
}, 200);
}
 
level1();
}());

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.