从 MDN Docs 学习 JS 遇到了“函数部分”中的代码。无法理解return;以下代码完成了什么
function foo(i) {
if (i < 0)
return; // what does this do?
console.log('begin: ' + i);
foo(i - 1);
console.log('end: ' + i);
}
foo(3);
Output
'begin: 3'
'begin: 2'
'begin: 1'
'begin: 0'
'end: 0'
'end: 1' // why are these printing
'end: 2' // this one
'end: 3' // this one
我理解了前 5 行输出,但无法理解为什么end: 0,1,2,3会出现?
请帮忙 !
天涯尽头无女友
MMTTMM
三国纷争
相关分类