Skip to content

Instantly share code, notes, and snippets.

@benaston
Created June 11, 2014 15:11
Show Gist options
  • Save benaston/149140ad8dce478f8311 to your computer and use it in GitHub Desktop.
Save benaston/149140ad8dce478f8311 to your computer and use it in GitHub Desktop.
Variable scoping
'use strict';
var x;
function Func() {
x = "foo";
var y = "bar";
}
Func();
console.log(x); //logs 'foo' because the scope chain is searched for a variable named `x` on line 6
console.log(y); //logs 'ReferenceError: y is not defined' because `y` is scoped to function Func
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment