Skip to content

Instantly share code, notes, and snippets.

@nordyke
Created January 5, 2012 17:28
Show Gist options
  • Save nordyke/1566259 to your computer and use it in GitHub Desktop.
Save nordyke/1566259 to your computer and use it in GitHub Desktop.
Global Variables
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