cgrinaldi
3/27/2015 - 12:24 AM

A simple example of hoisting with function expressions

A simple example of hoisting with function expressions

var sayHello;                    // currently undefined
sayHello();                      // undefined is not a function
sayHello = function() {          // only here is the variable assigned
  console.log('Hello, world!');  
};
sayHello();                      // will error out (see below for reason)
var sayHello = function() {
  console.log('Hello, world!');
};