Skip to content

Instantly share code, notes, and snippets.

@Hollyw00d
Created August 13, 2014 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hollyw00d/38c18fe83df7257d5044 to your computer and use it in GitHub Desktop.
Save Hollyw00d/38c18fe83df7257d5044 to your computer and use it in GitHub Desktop.
Hoisting Clarity Needed
/*
See "Hoisting Section" on:
http://dailyjs.com/2012/07/23/js101-scope/
*/
/*
**QUESTION**
Why does Code 1 evaluate to "undefined" and Code 2 evaulate to "1".
I thought both codes would evaluate to "1" because of hoisting.
*/
// CODE 1
function example() {
console.log(a);
var a = 1;
}
example();
// CODE 2
function example() {
var a = 1;
console.log(a);
}
example();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment