function declaration
One of the important features of the function declaration is the function declaration promotion (Functions declaration hoisting), which means that the function declaration is read before the code is executed. This means that the function declaration can be placed after the statement that called it, as follows:
1 sayhi (); The function is declared after the call statement (Functions declaration hoisting) 2 function Sayhi () {3 console.log ("Hello World"); 4
function Expression
There are many ways of expressing it, the following is the most common one:
var(AGR1, arg2) { + " + arg2);
As stated in the book, the function declares the statement that the function actually declares a variable F, then assigns a declared function object to the variable F, and the declaration of the variable has a feature that is raised to the top of all the code, so that functions declared by the function declaration statement can be called before the declaration.
As to why a function is also assigned to a variable, the function expression cannot be mentioned earlier. Let's analyze the following:
var s = function (Arg1, arg2) {};
Can be split into:
var s;s = function (Arg1, arg2) {}
It was var s
declared in advance, but s = xxxx
only when it was run here.
JS defines functions in two ways: function declaration and function expression