JavaScript:函数的声明与定义

1. 函数声明表达式

function test(args){
    
    
	...
}

2. 函数表达式(又叫函数字面量)

2.1 使用匿名函数赋值

var test = function() {
    
    
	...
}

2.2 使用具名函数赋值

var test = function test1() {
    
    
	console.log(1, 2);
	//可以在函数使用test1()内部调用该函数,外部不能使用
	//不过会出现死循环
	test1();
}
console.log(test.name);		//test1
test();		//会出现死循环
test1();  //报错

猜你喜欢

转载自blog.csdn.net/qq_45465526/article/details/121285849