Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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); // 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