Possible Duplicate:
JavaScript: var functionName = function() {} vs function functionName() {}
What’s the difference between:
function sum(x, y) { return x+y; } // and var sum = function (x, y) { return x+y; }
Why is one used over the other?
The first is known as a named function where the second is known as an anonymous function.
The key practical difference is in when you can use the sum function. For example:-
zis assigned 5 whereas this:-Will fail since at the time the first line has executed the variable sum has not yet been assigned the function.
Named functions are parsed and assigned to their names before execution begins which is why a named function can be utilized in code that precedes its definition.
Variables assigned a function by code can clearly only be used as function once execution has proceeded past the assignment.