Created
June 11, 2014 15:11
-
-
Save benaston/149140ad8dce478f8311 to your computer and use it in GitHub Desktop.
Variable scoping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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