JS——执行栈(压栈和出栈)

<script type="text/javascript">
	console.log('one'+i);	//变量的声明提升
	var i= 1;
	foo(1);		//函数声明提升
	function foo(i){
		if(i == 4){
			return
		}
		console.log('two'+i);	//压栈
		foo(i+1);	//递归调用
		console.log('three'+i);		//出栈
	}
	console.log('four'+i);	
</script>

以上代码依次输出:

oneundefined
two1
two2
two3
three3
three2
three1
four1

你可能感兴趣的:(JS)