Created
January 27, 2015 03:00
-
-
Save nulayuhz/1108efeaf7579abf2fb9 to your computer and use it in GitHub Desktop.
function declaration vs function expression
This file contains 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
function expression: | |
foo() //try to call foo TypeError! | |
var foo = function () { | |
// do something | |
}; | |
is more like: | |
var foo; | |
foo() //try to call foo TypeError! | |
foo = function() { | |
// do something | |
} | |
the variable (name identifier is hoisted), but the assignment is not; | |
function declaration: | |
foo(); | |
function foo() { | |
// no problem! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment