Hoisting

a quick example of hoisting

by Joseph Tate

HTML

<h1>Hoisting</h1>

<p id="first">The variable definition is first ...  </p>
<p id="second"> And then it is ... </p>

JavaScript

var num = 56;
function calculateSomething() {
    if (num === undefined) {
        num = 'undefined';
    }            
    $('#first').append(num); 
    var num = 12;
    $('#second').append(num);     
}

calculateSomething();