Skip to content

Instantly share code, notes, and snippets.

@Restuta
Last active August 29, 2015 14:06
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 Restuta/fae29de35554dcf7b785 to your computer and use it in GitHub Desktop.
Save Restuta/fae29de35554dcf7b785 to your computer and use it in GitHub Desktop.
JS local scope definition
<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