Created
August 2, 2012 07:32
-
-
Save micmath/3234884 to your computer and use it in GitHub Desktop.
Examine the code snippet below, without evaluating it. What would you expect to be consoled?
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
MyApp = 42; | |
(function() { | |
if (typeof MyApp === 'undefined') { | |
var MyApp = { oops: true }; | |
} | |
console.log(MyApp); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[Object]
Since the inner var declaration masks the global MyApp.
The declaration of var MyApp in the function happens before the If-statement, and there for is undefined.