input: "hello"
current input is "hello"
when function is called, the return value is added to the call stack
|-----------------------------|
| reverseString("ello") + "h" |
|-----------------------------|
move to the next recursion call
current input is "ello"
when function is called, the return value is added to the call stack
|-----------------------------|
| reverseString("llo") + "e" |
| reverseString("ello") + "h" |
|-----------------------------|
move to the next recursion call
current input is "llo"
when function is called, the return value is added to the call stack
|-----------------------------|
| reverseString("lo") + "l" |
| reverseString("llo") + "e" |
| reverseString("ello") + "h" |
|-----------------------------|
move to the next recursion call
current input is "lo"
when function is called, the return value is added to the call stack
|-----------------------------|
| reverseString("o") + "l" |
| reverseString("lo") + "l" |
| reverseString("llo") + "e" |
| reverseString("ello") + "h" |
|-----------------------------|
move to the next recursion call
current input is "o"
when function is called, the return value is added to the call stack
|-----------------------------|
| reverseString("") + "o" |
| reverseString("o") + "l" |
| reverseString("lo") + "l" |
| reverseString("llo") + "e" |
| reverseString("ello") + "h" |
|-----------------------------|
move to the next recursion call
current input is ""
since return value for this has hit the base case,
it will start executing by poping the top stack frame from the call stack
return result: ""
|-----------------------------|
| "" + "o" |
| reverseString("o") + "l" |
| reverseString("lo") + "l" |
| reverseString("llo") + "e" |
| reverseString("ello") + "h" |
|-----------------------------|
return result: "o"
|-----------------------------|
| |
| "o" + "l" |
| reverseString("lo") + "l" |
| reverseString("llo") + "e" |
| reverseString("ello") + "h" |
|-----------------------------|
return result: "ol"
|-----------------------------|
| |
| |
| "ol" + "l" |
| reverseString("llo") + "e" |
| reverseString("ello") + "h" |
|-----------------------------|
return result: "oll"
|-----------------------------|
| |
| |
| |
| "oll" + "e" |
| reverseString("ello") + "h" |
|-----------------------------|
return result: "olle"
|-----------------------------|
| |
| |
| |
| |
| "olle" + "h" |
|-----------------------------|
return result: "olleh"
|-----------------------------|
| |
| |
| |
| |
| |
|-----------------------------|