JavaScript Closures
The Story of the Lost Credit Card

A closure is formed when an inner function gets its hands on
free variables (by reference that is).

http://tech.pro/tutorial/1744/javascript-closures-or-the-story-of-the-lost-credit-card
The Happening
function carelessCitizen() {
var card = 3000;
function thievingPunk() {
card = card - 1500;
}
thievingPunk();
}
carelessCitizen();
Set up the CCTV
•
•
•
•
•
•
•

Fire up Google Chrome
Press F12
Go to Sources, Snippets
Right click, choose New
Name it card.js
Write debugger;
Add the rest of the code
Caught in The Act
Frame 1

Press F11
Caught in The Act
Frame 5

TED !!!
BUS
Dumitru Ungureanu
itmitica@gmail.com

JavaScript closures