Created
January 5, 2012 17:28
-
-
Save nordyke/1566259 to your computer and use it in GitHub Desktop.
Global Variables
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 global = "Global string"; | |
function firstFunction(){ | |
var local = "Local string"; | |
alert(global); //alerts out 'Global string' | |
alert(local); //alerts out 'Local string' | |
} | |
function secondFunction(){ | |
alert(global); //alerts out "Global string" | |
alert(local); //errors, because `local` is only accessible in `firstFunction` | |
} | |
alert(local); //errors, because `local` is only accessible in `firstFunction` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment