Skip to content

Instantly share code, notes, and snippets.

@malinky
Last active August 29, 2015 14:14
Show Gist options
  • Save malinky/2bf6430cd6deedee4ff8 to your computer and use it in GitHub Desktop.
Save malinky/2bf6430cd6deedee4ff8 to your computer and use it in GitHub Desktop.
Function Declarations and Expressions
/**
* See http://benalman.com/news/2010/11/immediately-invoked-function-expression/ for a better explanation
*/
<script>
function test() {
console.log('function declaration that is called with test()');
}
test();
(function test() {
console.log('immediately invoked function declaration wrapped in brackets (turned into an expression)');
})()
var test = function() {
console.log('immediately invoked function expression');
}()
var test = (function() {
console.log('immediately invoked function expression wrapped in brackets for convention');
}())
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment