Home > Article > Web Front-end > Function definition of javascript study notes_javascript skills
Function declaration
function funname( 参数 ){ ...执行的代码 }
The declarative function will not be executed immediately. It will only be executed after we call it: funname();
* Semicolon is used to separate executable JavaScript statements. Since the function declaration is not an executable statement, it does not end with a semicolon.
Function expression
var x = function( 参数 ){ ...执行的代码块 };
The function defined by the function expression is actually an anonymous function (this function has no name and is stored directly in a variable)
* A semicolon is required at the end of the function expression because it is an execution statement.
Function constructor
Call a function and assign it to a variable:
In actual production, it is not recommended to use constructors to define functions. We can rewrite the above example as:
The above is the entire content of this article, I hope you all like it.