+ 5
Functions in JavaScript
What's the difference between: #Declaring a named function eg: function foo(){}; and #Declaring an anonymous function and assigning it to a variable eg: var foo = function(){};
2 Respostas
+ 2
The former allows hoisting, which means you can use a function at the top of the code before it is declared somewhere in the bottom.
The latter doesn't.
+ 2
Both functions would be called as foo(). There isn't much of a difference. However, you could declare like this:
const foo = function() {}
to make foo() immutable, or unchangeable.