Re:“var functionName” vs “function functionName”
by ripter on Wednesday April 30, 2014 @01:46PM
(#7674964)
There aren't, the name of a function is optional (if you assign it to a variable.) So you can write:
function a() {}
// or
var a = function() {}
// or
var a = function a() {}
// or
obj.prototype.a = function() {}
// or
obj.prototype.a = function a() {}
There is little difference in the function declaration. The difference is if you named it or not.
The reason you have to be careful with the var a = function() {} forms is because variables are hoisted. So while the function will exist, your variable will not point to that function until the assignment happens.
The reason you have to be careful with the var a = function() {} forms is because variables are hoisted. So while the function will exist, your variable will not point to that function until the assignment happens.