Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var a = 1;
- var six = (function() {
- var foo = 6;
- return function() {
- // JavaScript "closure" means I have access to foo in here,
- // because it is defined in the function in which I was defined.
- alert(foo);
- };
- })
- ();
- six(); // alerts 6
- alert(a); // alerts 1
- alert(foo); // ReferenceError: foo is not defined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement