+ 2

It's a diference betwen this "gh = function (){}" and "function bg (){}"?

19th May 2018, 1:08 PM
Dracusorul
Dracusorul - avatar
2 Antworten
+ 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
19th May 2018, 8:01 PM
visph
visph - avatar
+ 2
nope its exactly the same thing gh=function(x,y){} function gh(x,y){} same thing,different method
19th May 2018, 1:19 PM
᠌᠌Code X
᠌᠌Code X - avatar