Created
August 13, 2014 22:03
-
-
Save Hollyw00d/38c18fe83df7257d5044 to your computer and use it in GitHub Desktop.
Hoisting Clarity Needed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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