Created
July 7, 2010 12:52
-
-
Save sofadesign/466645 to your computer and use it in GitHub Desktop.
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
// 1. | |
function foo(){ | |
function bar() {return 3;} | |
return bar(); | |
function bar() {return 8;} | |
} | |
alert(foo()); // 8 | |
// mais | |
// 2. | |
function foo(){ | |
var bar = function() {return 3;}; | |
return bar(); | |
var bar = function() {return 8;}; | |
} | |
alert(foo()); // 3 | |
/* | |
1. Using Function Declaration | |
- visible outside of it’s scope | |
- “Function declarations and function variables are always moved (‘hoisted’) to the top of their JavaScript scope by the JavaScript interpreter” | |
2. Using Function Expression | |
- not visible outside of it’s scope | |
Read more: <http://javascriptweblog.wordpress.com/2010/07/06/function-declarations-vs-function-expressions/> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment