// Variable declarations are hoisted to top of scope. // Variable assignments are not. // Outside of scope, hence ReferenceError console.log(foo); // ReferenceError: foo is not defined (function () { // Variable declaration got hoisted to top of scope, but the variable assignment did not, hence undefined console.log(foo); // undefined var foo = 'bar'; // After variable assignment console.log(foo); // 'bar' })();