Possible Duplicate:
JavaScript: var functionName = function() {} vs function functionName() {}
In JavaScript we can say:
function a() {};
Or we could say
var a = function() {};
Can anyone explain to me how exactly these differ, which, if any, is more preferable, and under what circumstances would one use each?
Any links or external reading would also be much appreciated.
A function expression is very similar to and has almost the same syntax as a function declaration (see function statement for details). The main difference between a function expression and a function declaration is the function name, which can be omitted in function expressions to create anonymous functions.
The function declaration (function statement) defines a function with the specified parameters. You can also define functions using the Function constructor and a function expression.
There are 3 ways of writing a function in JavaScript: Function Declaration. Function Expression. Arrow Function.
One is a function declaration and one is a function expression.
http://javascriptweblog.wordpress.com/2010/07/06/function-declarations-vs-function-expressions/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With