Last active
August 29, 2015 14:14
-
-
Save malinky/2bf6430cd6deedee4ff8 to your computer and use it in GitHub Desktop.
Function Declarations and Expressions
This file contains hidden or 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
/** | |
* 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