In the process of beginner JS, it is always impossible to distinguish what is function expression and what is function definition, which is detrimental to the compaction of basic knowledge. Therefore, the access to information, carefully distinguish it.
A brief summary is as follows:
1. Difference One: function is defined by functions, and others are function expressions;
2. Difference two: The function expression can omit the function name.
function functionname (formalparameterlist) {functionbody} // functions Definition
function [functionname] (formalparameterlist) {functionbody} //functions expression
In the actual application of the function, the function definition cannot be executed immediately, causing a syntaxerror syntax error, so the shirt resolves it to a function expression. That is, in the function definition Money plus any other symbol, the most common and not weird notation is before the parentheses, for example: (function GetName () {}). So will everyone associate with anonymous functions? By the same time, you can learn another knowledge: ' (function () {}) ' and ' (function () {} ()) ' Two functions, what is the difference between these two functions? We can take a look at what they have in common, and it's clear that they all have parentheses, compared to normal functions, and that the parentheses have 2 functions in javascript: one is to establish the priority of the operation and the other as the grouping operator. This is certainly not the former usage, the second is the latter one. At this time
(function() {}) (), which evaluates a function expression with parentheses and then participates in "function call";
(function () {} ()), a function call is evaluated with parentheses and then executed due to the end of the statement.
On the function definition and function expression in JS