Last active
August 29, 2015 14:06
-
-
Save Restuta/fae29de35554dcf7b785 to your computer and use it in GitHub Desktop.
JS local scope definition
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
<html> | |
<body> | |
<script> | |
/* this function will be accessible through global scope, which is a bad practice | |
meaning you will be able to call it through window.bla() */ | |
function bla() { | |
console.log('bla function'); | |
} | |
</script> | |
<script> | |
(function() { | |
console.log('gets executed 2'); | |
var bla = {}; | |
/* while this function is inside another scoped object (another function) all stuff defined here won't be visible from outside | |
so you won't be able to call window.foo()*/ | |
function foo() { | |
console.log('this definition won\'t get executed'); | |
} | |
})(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment