What do you think, which one is the better, faster, nicer solution to declare a function?
First:
(var) myFunction = function(){
//Stuff to do
};
or Second:
function myFunction() {
//Stuff to do
};
Both will work in JavaScript and JQuery. But what do you think is better?
Note that both behave differently – functions defined by
functionstatement are defined before the code executes.but
(Have you also noted where I did and where I didn’t use semicolon?)
Also, function statements (the second option) are forbidden in blocks. It is not defined how the following should work:
thus it’s possible that function
fwill be, although illogically, declared in some browsers. However, it’s permitted to do the following:Next time better search before asking a question, var functionName = function() {} vs function functionName() {}