Skip to content

Instantly share code, notes, and snippets.

@jkoppel
Created Sep 18, 2016
Embed
What would you like to do?
// Version 1: Prints "1"
function foo() {
x = 1;
}
foo();
console.log(x);
//------------------------------------
// Version 2: Gives "ReferenceError: x is not defined"
function foo() {
x = 1;
var x = 2;
}
foo();
console.log(x);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment