Created
July 19, 2011 11:31
-
-
Save oslego/1092039 to your computer and use it in GitHub Desktop.
Global scoping of JavaScript variables
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
<script type="text/javascript"> | |
function fn(){ | |
//missing var declaration exposes 'x' to global scope | |
x = "surprise!" | |
//by using var 'y' remains private inside the instance of 'fn' | |
var y = "really private!" | |
} | |
var inst = new fn() | |
console.log(x) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment