|
|
|
|
|
by killahpriest
4862 days ago
|
|
function myFunction(arg1, arg2) {}; // This is OK, but...
var myFunction = function(arg1, arg2) {}; // This is best!
The second option is better, and is properly scoped, but it leads to certain syntax problems once you get into closures.What problems? How does assigning the function to a variable help avoid needing to make a closure for this? |
|
EDIT: To clarify:
All variable declarations in Javascript do indeed get hoisted to the top of the scope, but with function declarations even the function value itself gets hoisted. So for instance, this returns 'two':
But this returns 'one':