Created
May 6, 2015 19:05
-
-
Save heronmedeiros/6fb2dc2824ba64a2776f to your computer and use it in GitHub Desktop.
How to encapsulate js code
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
(function() { | |
var x = ''; | |
function myFunction() { | |
console.log('Hello: ' + x); | |
} | |
x = 'Bob'; | |
myFunction(); | |
log(typeof x); // string | |
log(typeof myFunction); // function | |
})(); | |
log(typeof x); // undefined | |
log(typeof myFunction); // undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment