Tuesday 11 April 2017

javascript recursive stack overstack

Is there anybody would explain why the result is different below?

// test one
function computeMaxCallStackSize() {
    try {
        return computeMaxCallStackSize() + 1;
    } catch (e) {
        return 1;
    }
}

console.log(computeMaxCallStackSize()); // the result is **17958**

// test two
function computeMaxCallStackSize() {
    try {
        return 1 + computeMaxCallStackSize();
    } catch (e) {
        return 1;
    }
}

console.log(computeMaxCallStackSize()); // the result is **15714**

When the position of the function 'computeMaxCallStackSize' is different,the result is different too. What's the reason? Thanks very much! Running environment: node.js v6.9.1 OS:Win7



via myzhou

No comments:

Post a Comment