Variable Hoisting
http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html
by Joseph Tate
HTML
<p id="hoisted">Hoisted: </p>
<p id="not-hoisted">Not hoisted: </p>
JavaScript
// Notice that the assignment portion of the declarations were not hoisted.
//http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html
function hoisted () {
var foo = 'foo';
function hoistIt() {
foo = 'bar';
};
hoistIt();
$('#hoisted').append(foo);
}
function notHoisted () {
var foo = 'foo';
function hoistIt() {
var foo = 'bar';
};
hoistIt();
$('#not-hoisted').append(foo);
}
hoisted();
notHoisted();