There are a few differences, mostly pragmatic. When you 'var' a function, the normal assumption is some kind of 'locally' scoped function ( think a nested function ). When you do, function myFunction() {}
, the function is mostly assumed to be globally scoped (though you could wrap this inside an anonymous function as well).
In the case of a javascript 'class', if you want to create a locally scoped function, you would have to use 'var' to declare it.
var myClass = function() {
var test = function() {
//This function has local scope
}
};
Adding to the above comments, this is a simple example.
var myVariable = resultFunction();
function resultFunction() {
return 1;
}
The above code will work. But you can't do the following
var myVariable = resultFunction();
var resultFunction = function() {
return 1;
};
But you can do
var resultFunction = function() {
return 1;
};
var myVariable = resultFunction();