This question already has an answer here:
- What is the (function() { } )() construct in JavaScript? 23 answers
I've been trying to understand exactly how IIFEs work in regards to anonymous functions. I understand their use in avoiding global variable collisions and that they create their own local scope.
I'm not clear on what happens when an anonymous function like this is called.
(function () {
var myVar = 'foo';
}
)()
If this is immediately invoked and it is not available in the global scope, where is it available? How would I access myVar?