When the parser loads data like an execution environment, it is not the same for function declarations and function expressions, and the parser first reads the function declaration and then executes the call to the function.
1: function declaration
alert (sum10,10);
function sum (num1,num2) {
return num1+num2;
}
This function works as expected, because the parser will raise the declaration function to the top of the source tree before the code executes.
Therefore, the function is executed first, and then the call to execute the function
2. Function expressions
Alert (sum 10, 10)
var sum=function sum (num1,num2) {
return num1+num2;
}
The above code generates an error during run time, because the reference to the function is not saved in the variable sum until the statement that contains the function is executed.
And because the first line of code can also cause errors.
There is no other difference than when you can pass the variable access function.
The difference between a function declaration and a function expression