Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Local and global variable scope
var greeting = "Hi, I am a global variable"; // global scope variable
function sayHello() {
var greeting = "Hi, I am a local variable"; // local scope variable
console.log(greeting);
}
sayHello(); // Prints "Hi, I am a local variable"
console.log(greeting); // Prints "Hi, I am a global variable"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment