Skip to content

Instantly share code, notes, and snippets.

@lenafaure
Created April 30, 2017 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lenafaure/e0ec3542bcfa5086b0c5145e4ccc5b73 to your computer and use it in GitHub Desktop.
Save lenafaure/e0ec3542bcfa5086b0c5145e4ccc5b73 to your computer and use it in GitHub Desktop.
The var keyword and the scope
var myVariable = "Hi, I am a global variable";
function sayHello() {
myVariable = "Hi, I am locally produced!";
console.log(myVariable);
}
console.log(myVariable); // Prints "Hi, I am a global variable"
sayHello(); // Prints "Hi, I am locally produced!"
console.log(myVariable); // Prints "Hi, I am locally produced!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment