Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sofadesign/466645 to your computer and use it in GitHub Desktop.
Save sofadesign/466645 to your computer and use it in GitHub Desktop.
// 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