function test(param, n) {
console.log(param, "start --- ", n);
if (n > 1) {
console.log(param, "before first recursion --- ", n);
test("test-1", n - 1);
console.log(param, "after first recursion --- ", n);
test("test-2", n - 1);
console.log(param, "after second recursion --- ", n);
}
console.log(param, "end --- ", n);
}
test("initialize", 3);
In output console
test-1 after first recursion --- I am getting value 2, can someone please explain the flow of code is going as, I was expecting 3 as the output, because in my understanding if the test("test-1", n-1) is completed then the next call i.e. test("test-2", n-1) will be getting 3 value as fresh input, also is the js working synchronous here ?