In a new recursion, a variable declared with "let", should be initialized with a new "let", but in below's demo, it didn't. it seems executed like "var" instead of "let". so when it runs, it would be "Maximum call stack size exceeded...".
let cur;
for(let i=5,last=()=>{};i>=0;i--){
cur = ()=>{
console.log(i);
last()
};
last = cur;
}
cur()
however, by this way, the result executed as expected.
let cur;
for(let i=5,last=()=>{};i>=0;last = cur,last = cur,i--){
cur = ()=>{
console.log(i);
last()
};
}
cur()
In a new recursion, a variable declared with "let", should be initialized with a new "let", but in below's demo, it didn't. it seems executed like "var" instead of "let". so when it runs, it would be "Maximum call stack size exceeded...".
however, by this way, the result executed as expected.