Possible duplicate:JavaScript: var functionName = function () {} vs function functionName () {}
In JavaScript, we can say:
function a() {};
Or we could say
var a = function() {};
Can someone explain to me exactly how they differ, which, if any, are preferable and under what circumstances can each of them be used?
Any links or external readings will be highly appreciated.
One is a function declaration, and one is a function expression.
http://javascriptweblog.wordpress.com/2010/07/06/function-declarations-vs-function-expressions/
First
FunctionDeclaration FunctionExpression. , FunctionDeclaration FunctionExpression, , .
# 1)
0,function a() {} //FunctionExpression
# 2)
(function a() {} ()); //FunctionExpression
№ 3)
var b = function a() {}; //FunctionExpression
# 4)
foo(function a(){}); //FunctionExpression
FunctionExpression .
1)
2)
:
http://sweatte.wordpress.com/syntax/javascript-idioms-and-gotchas/
http://www.ecma-international.org/publications/standards/Ecma-262.htm
one - , - , . - javascript-.