I try following simple JavaScript nested code, while the result is confusing.
Anyone can give a detail explanation? Thanks very much.
I am waiting...
<script>
// args = [];
function foo (param) {
args= [];
if (param <= 1) {
args.push(foo(2));
} else {
return param;
}
}
foo(1)
</script>
The final args is [], I guess the outer args (is [2]) is overwritten by the nested inner args (which is []). Who can give a detail explanation about the result? How is the execution sequences? Thanks.
argsafter callingfoo(1)is [2]. Take a look at the console output of this JSFiddle