window.onload = function() {
var count = 0;
var message = "You clicked me ";
var div = document.getElementById("message");
var button = document.getElementById("clickme");
button.onclick = function() {
count++;
div.innerHTML = message + count + " times!";
};
};
Once the function assigned to the onload property has been executed the var div should become unreachable. Then why the hack the function assigned to the onclick property can still use the variable in question? The function executes only after the button has been clicked (var button).