Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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