Here is a direct comparison ...
function myObject() {
This declares a function when parsing JavaScript ...
var myObject = function () {
This declares a function at runtime.
If you use the var method, your function must be declared before using it ... try this example.
myFunction(); // Works myVarFunction(); // Boom var myVarFunction = function () { alert("Hi"); }; function myFunction() { alert("Hi"); };
So why use the "var" method if you need to be more careful to use it? It all depends on the scope ... features with advanced features are considered the best.
UPDATE: And here are some great explanations:
var functionName = function () {} vs function functionName () {}
Fenton
source share