i call myFunc1 with counter val 2. myFunc1 calls myFunc2 and increases each time counter.
It should stop when counter val is 4.
Why does this not work?
I get error "Maximum call stack size exceeded"
myFunc1 = (counter) => {
if(counter < 5) {
myFunc2(counter);
}
}
myFunc2 = (counter) => {
myFunc1(counter++);
}
myFunc1(2);
counter++ returns the value of counter and then increments the variable. You should use counter + 1 or ++counter which increments, then returns the value.
see more info
myFunc1 = (counter) => {
if(counter < 5) {
myFunc2(counter);
}
}
myFunc2 = (counter) => {
myFunc1(counter + 1);
}
myFunc1(2);