Other ways to define functions
Named function: If the function has a name, it is a named function
Anonymous function: If the function does not have a name, it is an anonymous function
Another way to define a
function Function expression: Give a function to a variable, and a function expression 3 var variable
is formed at this time
= Anonymous function
If it is a function expression, then the variable stored in the previous variable is a function
and this variable is equivalent to a function, which can be called directly by adding parentheses
Note:
After the function expression, after the assignment, a semicolon is required
//命名函数:
function f1(){
console.log("命名函数")
}
//匿名函数:
var f1= function (){
console.log("匿名函数")
}
//函数声明
function f1(){
console.log("我是函数声明")
}
f1()//函数调用
function f1(){
console.log("我是函数声明")
}
f1()
//命名函数重名的时候,下面的函数会覆盖上面的函数
//函数表达式
var f2 =function (){
console.log("我是一个函数表达式")
}
f2()
f2=function (){
console.log("我也是一个函数表达式")
}
f2()
//函数表达式调用的时候,会调用自己上面的函数表达式,不会被覆盖
//函数的自调用
(function () {
console.log("阿涅哈斯诶呦");
})();
(function () {
console.log("嘎嘎")
})();
//只可以一次性调用函数