I am trying to explain to a student I am helping out at school with an ICT exam question on Javascript how the function below is returning 24. I am an economics teacher by training who dabbles in programming.(我试图向学生解释我正在学校中通过Javascript进行ICT考试的问题,以帮助下面的函数恢复正常。24.我是一名经济老师,受过培训,涉猎编程。)
I know it is a simple example of recursion but I am not sure of the actual step by step process and the scoping of the variable N. Is anyone able to explain step by step and clearly how this is working.(我知道这是一个简单的递归示例,但是我不确定实际的逐步过程和变量N的作用域。是否有人能够逐步解释并清楚其工作原理。)
function mystery(n){
if(n==0)
return 1;
return n* mystery(n-1);
}
console.log(mystery(4));
ask by jon translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…