There are several differences, mostly pragmatic. When you have a "var" function, a normal assumption is a kind of "locally" scoped function (I think a nested function). When you do this, function myFunction() {} , the function is basically considered a global scope (although you can wrap it inside an anonymous function as well).
In the case of the javascript class, if you want to create a locally restricted function, you will need to use "var" to declare it.
var myClass = function() { var test = function() {
Adding to the comments above is a simple example.
var myVariable = resultFunction(); function resultFunction() { return 1; }
The above code will work. But you can not do the following
var myVariable = resultFunction(); var resultFunction = function() { return 1; };
But you can do
var resultFunction = function() { return 1; }; var myVariable = resultFunction();
source share