The function declaration in JS refers to the following form:
function functionname () {
}
This way to declare a function, and a function expression is like an expression to declare a function, such as:
var functionname = function () {
}
Probably many friends in see these two kinds of writing will produce the doubt, these two kind of writing similar, in the application seemingly also all is feasible, then they have what difference?
In fact, the JS parser does not treat the function declaration and function expression equally. For function declarations, the JS parser will be read first, make sure that the declaration has been resolved before all the code executes, and that the function expression, like a variable that defines other basic types, is parsed only as it executes to a sentence, so in practice they are still different, specifically, When you use the form of a function declaration to define a function, you can invoke the method after the function declaration, and the latter, if you do so, will make an error.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/