Consider following code snippet:

var result = 0;
function AddValue(x) {
    result = result + x;
    return result;
}
console.log(AddValue(AddValue(10)));
What will be printed to the console?
Explanation
Variable result declared in global scope. first function invoke: result = result + x; // result = 0 + 10; second function invoke: result = result + x; // result = 10 + 10;

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback