Skip to content

Instantly share code, notes, and snippets.

@greggnakamura
Created September 9, 2014 04:52
Show Gist options
  • Save greggnakamura/fa3c88bbf1f311fb5cc2 to your computer and use it in GitHub Desktop.
Save greggnakamura/fa3c88bbf1f311fb5cc2 to your computer and use it in GitHub Desktop.
Javascript: Self-invoking anonymous function example
// Immediately invoked function
// Code treated as local variables and functions
// Anonymous function, wrapped by a set of parenthesis, allows execution of anonymous function
(function () {
var foo = 'hello, window';
var bar = function () {
var foo = 'hello, function';
alert(window.foo); // returns undefined
};
bar();
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment