Skip to content

Instantly share code, notes, and snippets.

@oslego
Created July 19, 2011 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oslego/1092039 to your computer and use it in GitHub Desktop.
Save oslego/1092039 to your computer and use it in GitHub Desktop.
Global scoping of JavaScript variables
<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