Created
February 6, 2012 16:38
-
-
Save laustdeleuran/1753169 to your computer and use it in GitHub Desktop.
Scoped variables example
This file contains 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
var globalScope = "I'm in the global scope"; | |
var scopedFunction = function(){ | |
var localScope = "I'm not in the global scope"; | |
console.log(localScope); | |
}; | |
console.log(globalScope); | |
// Outputs "I'm in the global scope" | |
scopedFunction(); | |
// Outputs "I'm not in the global scope"; | |
console.log(localScope); | |
// Fails - is 'undefined' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment