Skip to content

Instantly share code, notes, and snippets.

@cgrinaldi
Last active August 29, 2015 14:17
Show Gist options
  • Save cgrinaldi/c87971ea3411d8c3f89b to your computer and use it in GitHub Desktop.
Save cgrinaldi/c87971ea3411d8c3f89b to your computer and use it in GitHub Desktop.
A simple example of hoisting with function expressions
sayHello(); // will error out (see below for reason)
var sayHello = function() {
console.log('Hello, world!');
};
var sayHello; // currently undefined
sayHello(); // undefined is not a function
sayHello = function() { // only here is the variable assigned
console.log('Hello, world!');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment