+ 2
It's a diference betwen this "gh = function (){}" and "function bg (){}"?
2 Réponses
+ 6
Yes there's a tiny, but important difference: first is stored in (assigned to) a variable, and second is not... even if both are accessible through an equivalent identifier, that make a difference on when and where each are accessible (callable) in a script, because JS is parsed in two times. At first pass, all named function declarations (the second type in your example) are parsed (as well as all variable declarations, but not their assignation), so they could be called even the code is after the lines calling them, but assigned function declaration are only available after the lines where/when the variable assignation occurs (an assigned function declaration is only parsed at the second pass / runtime):
gh(); // throw an error
bg(); // still works
gh = function() { };
function bg() { };
gh(); // now works
+ 2
nope its exactly the same thing
gh=function(x,y){}
function gh(x,y){}
same thing,different method